1
Is appearing the error:
Type error: Argument 1 passed to Illuminate Database Eloquent Model::update() must be of the type array, Object Given, called in /var/www/html/Laravel/app/Http/Controllers/Propertycontroller.php on line 89
Controller:
<?php
namespace Laravel\Http\Controllers;
use Laravel\Property;
use Illuminate\Http\Request;
use Laravel\Http\Controllers\Controller;
class PropertyController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$properties = Property::all();
return view('/property/index')->with('properties', $properties);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('/property/create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$property = new Property;
$property->nome = $request->nome;
$property->proprietario = $request->proprietario;
$property->valor = $request->valor;
$property->save();
return redirect()->action('PropertyController@create');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$property = Property::find($id);
return view('/property/edit')->with('property', $property);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$property = Property::find($id);
$property->update($request);
return redirect()->action('PropertyController@index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$property = Property::find($id);
$property->delete();
return redirect()->action('PropertyController@index');
}
}
Route:
<?php
Route::get('/', function () {
return view('auth/login');
});
Route::get('property/index', 'PropertyController@index');
Route::get('property/create', 'PropertyController@create');
Route::post('property/store', 'PropertyController@store');
Route::get('property/show', 'PropertyController@show');
Route::get('property/edit/{id}', 'PropertyController@edit');
Route::post('property/update/{id}', 'PropertyController@update');
Route::get('property/destroy/{id}', 'PropertyController@destroy');
Form:
@extends('app')
@section('content')
<form method="post" action="/property/update/{{$property->id}}" class="container">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="exampleInputEmail1">Nome</label>
<input type="text" class="form-control" name="nome" value=" {{$property->nome}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Proprietário</label>
<input type="text" class="form-control" name="proprietario" value="{{$property->proprietario}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Valor</label>
<input type="text" class="form-control" name="valor" value=" {{$property->valor}}">
</div>
<button type="submit" class="btn btn-default">Alterar</button>
</form>
@endsection
Now you’re giving msg: Massassignmentexception in Model.php line 445: _token
– Marcelo
@Marcelo then use like this
$request->except(['_token'])
I’ve already done the editing– novic
@Marcelo if given error and more fields add the in the array
$request->except(['_token','outro nome'])
; and you set up$fillable
of your model?– novic
Using the second way returned: name
– Marcelo
@Marcelo I did not understand, next put in your question your model and also the structure of your table please?
– novic
My model is empty.
– Marcelo
It was the model, I put protected $fillable = array('name', 'proprietary', 'value'); and it worked.
– Marcelo
@Marcelo never use
model
no configuration, made the edit in reply.– novic