来自laravel文档// Create a new user in the database...$user = User::create(array('name' => 'John'));媒体模型<?phpclass 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); }}解决方案您需要设置使用create,fill或update的>大量分配.参见此答案.删除您的guarded属性,并创建一个名为fillable的新属性,作为一个数组,其中包含允许通过批量分配进行更新的字段.protected $fillable = ['title', 'url'];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/eloquentFrom laravel docs// Create a new user in the database...$user = User::create(array('name' => 'John'));Media Model<?phpclass 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); }} 解决方案 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']; 这篇关于Laravel创建方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 07:20