Error is appearing:
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