I assume you used
$request = Input::all();
Try this instead
$request = Input::except('_token');
Btw, it is interesting that the token is ignored when using the 'create' method, but not when using the 'insertGetId' method...
Firstly thanks for the response.
I had another look at this, and basically I am mixing up Eloquent and Query builder. Looking at the documentation if using Eloquent I would use:
$id = Product::create($request->all())->id; //this inserts the values and returns the id
which ignores the token and adds the timestamps etc.
The insertGetId uses query builder, hence I need to assign the values I want inserted.
Thanks ps. the reason I'm using:
$request->all();
instead of
Input::all();
as thats just what the official documentation shows for laravel 5.0
Yes, I provided code for Laravel 4, because this is still the one mostly used and for production. Anyhow, the 'except' method exists also in Laravel 5.
Next assumption, you are inject the 'Request' class in your controller. The syntax should then be
public function xy(Request $request)
{
$all_data_except_token = $request->except('_token');
$id = Product::insertGetId($all_data_except_token);
// do or return something
}
The 'Request' is always the same. You can use all fake static methods described in the doc and access the object with them ;) http://laravel.com/docs/5.0/requests
I didn't know about except this will be handy in the future, and yes I was using the request controller.
Thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community