Laravel inserting new record Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Laravel inserting new record without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a problem with inserting new record to data

There is a part of videocontroller:

  $galleryName = Input::get('name');
  $galleryID = Foto::create($galleryName);

here model:

class Foto extends Eloquent {

    public static function create($name)
        return DB::table('galleries')->insert_get_id(array('name' => $name));

Declaration of Foto::create() should be compatible with

IlluminateDatabaseEloquentModel::create(array $attributes)

What I should fix?


Eloquent’s create method takes an array. You cannot change that.

If you need this functionality, create a different method:

public static function createFromName($name)
    return DB::table('galleries')->insertGetId(compact('name'));

Then use that in your controller:

$galleryName = Input::get('name');

$galleryID = Foto::createFromName($galleryName);
We are here to answer your question about Laravel inserting new record - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji