Laravel began to learn quite recently, and it is not very clear how to add data to the table. Here's what's in the controller:

public function admin(){ $add_event = new Add_Event(); if (Request::has('Title')) { if($add_event->add_to_base()){ $add_event->fill(Request::all()); }else{ } } return view('Admins'); } 

Here's what's in the model:

 namespace App\Models; use Illuminate\Database\Eloquent\Model; class Add_Event extends Model { protected $table = 'All_Events'; protected $fillable = array('Title', 'Description','Location'); public function add_to_base(){ return $this->save(); } } 

In the lessons, the guys use Input ::, but, as I understand it, they already sawed it out.

  • What is laravel? 5.x? - naym

1 answer 1

What is laravel? 5.x?

In 5, to save an object to the database, simply call the save () method of this object.

 $add_event->save(); 

PS Name the classes in the style of StudlyCaps and variables in camelCase and do not use snake_case in the code.

Read PSR