Answer the question
In order to leave comments, you need to log in
How to implement ORM in Laravel?
Routing - routes.php file:
Route:post(/add,[
'as'=>'add',
'uses'=>'[email protected]'
]);
class AddController extends BaseController{
$data=Input::all() //В $data записываем все сохраненные данные с нашей формы в виде ассоциативного массива
People::addPost($data); //Вызываем функцию в нашей модели,где в качестве параметра у нас наша переменная $data
}
Class People extends Eloquent{
public $timestamps = false; // нету столбцов(с датой обновление и загрузки записей) которые по умолчанию в laravel
protected $fillable = array(
'name',
'surname',
'message '
); // добавляем доступ к добавлению к данным столбцам
public static function addPost($data){
$add = People::create($data); //Добавляем наши новые записи в бд
return $add;
}
}
....
{{Form:open(array('url'=>action('[email protected]')))}}
{{Form:text('name',null)}}
{{Form:text('surname',null)}}
{{Form:text('message ',null)}}
{{Form:submit('Отправить',null)}}
{{Form::close()}}
Answer the question
In order to leave comments, you need to log in
I have not worked with Laravel, but if I understand you correctly, you need to link tables
In Eloquent, table relationships are written directly into the model:
сlass People extends Eloquent {
public function information() {
return $this->hasMany('Information')
}
}
сlass Information extends Eloquent {
public function people() {
return $this->hasOne('People')
}
}
People::all()->with('information')->get();
And you don’t have the addPeople function in the AddController function and everything is written like that, as you posted it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question