4

I'm trying to store an array using Laravel's create method

$input = Input::all();
$new_media = $this->media->create($input);

or

$input = Input::all();
$new_media = Media::create($input);

both codes does not work.

This is the error I'm getting.

Method [create] does not exist.

Laravel documentation here http://laravel.com/docs/4.2/eloquent

From laravel docs

// Create a new user in the database...
$user = User::create(array('name' => 'John'));

Media Model

<?php

class Media extends Eloquent {

    protected $table = 'media';

    protected $guarded = array();

    public static $rules_video = array(
        'title' => 'required',
        'url' => 'required'
    );
    public static $rules_image = array(
        'title' => 'required'
    );

    public function category(){
        return Category::find($this->category_id);
    }

}
6
  • Does the Media model extends Eloquent ? Commented Dec 4, 2014 at 11:45
  • I guesss there is no such method, instead you can use something like this $user = new User; $user->name = 'John'; $user->save(); where User is your model class which is extending Eloquent Commented Dec 4, 2014 at 11:46
  • @Richie Yes it does! Commented Dec 4, 2014 at 11:47
  • @HaykAghabekyan Right, but this method used to work fine. Just don't know what's wrong now. Commented Dec 4, 2014 at 11:48
  • edit your question to include your Media model Commented Dec 4, 2014 at 11:50

1 Answer 1

12

You need to setup Mass Assignments when using create, fill or update. See this answer.

Remove your guarded property and create a new one called fillable as an array with the allowed fields to be updated with mass assignments.

protected $fillable = ['title', 'url'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.