传递给Illuminate \ Database \ Eloquent \ Relations \ BelongsToMany :: formatRecordsList()的参数1必须是数组类型,给出null

时间:2017-03-28 22:11:01

标签: laravel

我在Laravel 5.4上遇到此错误。我为我的博客创建了标签,但我唯一得到的是错误。

[error] (compile:compileIncremental) Compilation failed
[info] Compiling 1 Scala source to C:\repos\scala\SocerGladiatorWeb\target\scala-2.11\classes...
[error] C:\repos\scala\SocerGladiatorWeb\app\controllers\RegisterController.scala:56: type mismatch;
[error]  found   : Throwable => play.api.mvc.Result
[error]  required: PartialFunction[Throwable,?]
[error]           e => handleRegisterError(e)
[error]             ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed

这是我的标签型号:

public function category()
{
    return $this->belongsTo('gamstec\Category');
}

public function tags()
{
    return $this->belongsToMany('gamstec\Tag');
}

现在这是我的PostController.php:

public function Posts()
{
    return $this->belongsToMany('gamstec\Post');
}

商店功能:

public function create()
{
    $categories = Category::all();
    $tags = Tag::all();
    return view('posts.create')->withCategories($categories)->withTags($tags);
}

这是标签箱形式:

我试图删除

public function store(Request $request)
{

    // validate the data
    $this->validate($request, array(
    'title'         =>      'required|max:255',
    'slug'          =>      'required|alpha_dash|min:5|max:255|unique:posts,slug',
    'body'          =>      'required',
    'stickers'      =>      'required|min:1|max:20',
    'category_id'   =>      'required|integer',
    'postimg'       =>      'required'
));

    // store in database
    $post = new Post;

    $post->title        =       $request->title;
    $post->slug         =       $request->slug;
    $post->body         =       $request->body;
    $post->stickers     =       $request->stickers;
    $post->category_id  =       $request->category_id;
    $tags               =       $request->input('tags', []);
    $post->postimg      =       $request->postimg;

    $post->save();

    $post->tags()->sync($request->tags, false);

    Session::flash('success', 'La publicación se ha creado correctamente');

    // redirect to another page
    return redirect()->route('posts.show', $post->id);
}

和同样的错误。

这是我的标签克里特选择表格:

$tags =  $request->input('tags', []);

所以在select表单上我把{{ Form::label('tags', ' Etiqueta', ['class' => 'fa fa-tags']) }} <select class="form-control select2-multi" name="tags[]" multiple="multiple"> @foreach($tags as $tag) <option value='{{ $tag->id }}'>{{ $tag->name }}</option> @endforeach </select> 放在一个空数组中,将数据传递给一个数组,但仍无效。

0 个答案:

没有答案