Laravel 5 Mass Assignment error

Hi,

I am learning laravel 5 framework and i am trying to update a record using a form.
https://laracasts.com/series/laravel-5-fundamentals/episodes/13

In my article controller I have this:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;// shortcut used => use Request;

use App\Article;
use App\Http\Requests;
use App\Http\Controllers\Controller;
//use Request;

class ArticlesController extends Controller
{
    public function index()
    {
        //return 'get all articles';
        //$articles = Article::order_by('created_at', 'desc')->get();// -nu merge
       // $articles = Article::latest('created_at')->get();
        $articles = Article::latest('created_at')->published()->get();
        
        //return $articles;
       // return view('articles.index')->with('articles',$articles);
        return view('articles.index', compact('articles'));
    }
    
    
    public function show($id)
    {

        $article=Article::findOrFail($id);
        return view('articles.show', compact('article'));
        //return $article;
        //return $id;
    }
    
    
    public function create()
    {

        return view('articles.create');
    }
    
    
    public function store(Requests\CreateArticleRequest $request)
    {

        $input = Request::all();
        
        //Article::create($input);
        
        $article = new Article;
        $article->title = $input['title'];
        $article->body = $input['body'];
        $article->publish_at = $input['publish_at'];
        $article->save();
        
        return redirect ('admin/articles');
    }
    
    
    public function edit($id)
    {

        $article = Article::findOrFail($id);
        
        return view ('articles.edit', compact('article'));
    }
    
    
    public function update($id, Request $request)
    {

       $article = Article::findOrFail($id);
       $article->update($request->all());
        
        return redirect ('admin/articles');
    }
    
}

Open in new window


When I am trying to update (update method) I receive the following error

MassAssignmentException in Model.php line 424:
_method
in Model.php line 424
at Model->fill(array('_method' => 'PATCH', '_token' => 'kNo1s676a5jUvGG0z52FjUB5LJWefQfR2jZREQr8', 'title' => 'ewrwere', 'body' => '12334cffff', 'publish_at' => '2015-11-15')) in Model.php line 1454
at Model->update(array('_method' => 'PATCH', '_token' => 'kNo1s676a5jUvGG0z52FjUB5LJWefQfR2jZREQr8', 'title' => 'ewrwere', 'body' => '12334cffff', 'publish_at' => '2015-11-15')) in ArticlesController.php line 76


I you have any ideas please help me.
Thank you,
Cristian
Qw MAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
By default, Eloquent models protect against mass-assignment.  If you want to make parts of the model open to mass assignment, you can do that at the time you create the model.  You use $guarded and $fillable (these are arrays of column names) to specify blacklists and whitelists.

http://laravel.com/docs/5.1/eloquent#mass-assignment
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Laravel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.