Laravel non-object - laravel

I create simple Laravel project. In blog view I have pages index (where is first page of last 5 blogs), Edit, Show, and Create. Now, all working fine if I create new Blog from database (edit/delete and show/read). But I can't create new blog from site. Do you see problem?
BlogControllor
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('blog.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'naslov'=>'Required',
'slug'=>'Required|alpha_dash|min:5|max:255|unique:blogs,slug',
'opis'=>'Required',
'tekst'=>'Required',
'upload_slike' => 'sometimes|image'
]);
$blog = new Blog;
$blog->naslov = $request->naslov;
$blog->slug = $request->slug;
$blog->opis = $request->opis;
$blog->tekst = $request->tekst;
//Sacuvaj novu sliku za blog post
if ($request->hasFile('upload_slike')) {
$image = $request->file('upload_slike');
$filename = time() . '.' . $image->getClientOriginalExtension();
$location = public_path('slike/' . $filename);
Image::make($image)->resize(800, 400)->save($location);
$blog->image = $filename;
}
$blog->save();
return redirect('blog');
}
Route
Route::resource('blog', 'BlogController');
Button on index page for create new Blog
Dodaj novu vest
Page create.blade.php
#extends('layouts.bez-sidebar')
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
tinymce.init({
selector: 'textarea',
plugins: 'link image',
menubar: false
});
</script>
#section('content')
{!! Form::open(['url'=>'blog','class'=>'form-horizontal', 'files' => true]) !!}
<div class="">
<div class="form-group">
{!! Form::label('naslov', 'Naslov', ['class'=>'control-label col-md-2']) !!}
<div class="col-md-10">
{!! Form::text('naslov', null, ['class'=>'form-control', 'placeholder'=>'Unesi naslov']) !!}
{!! $errors->has('naslov')?$errors->first('naslov'):'' !!}
</div>
<div class="form-group">
{!! Form::label('slug', 'Alias:', ['class'=>'control-label col-md-2']) !!}
<div class="col-md-10">
{!! Form::text('slug', null, ['class'=>'form-control', 'required' => '', 'minlenght' => '5', 'maxlenght' => '255', 'placeholder'=>'Unesi alias link za post']) !!}
{!! $errors->has('slug')?$errors->first('slug'):'' !!}
</div>
</div>
<div class="form-group">
{!! Form::label('opis', 'Opis', ['class'=>'control-label col-md-2']) !!}
<div class="col-md-10">
{!! Form::text('opis', null, ['class'=>'form-control', 'placeholder'=>'Ovde upisite kratak opis vesti']) !!}
{!! $errors->has('opis')?$errors->first('opis'):'' !!}
</div>
</div>
<div class="form-group">
{!! Form::label('tekst', 'Tekst', ['class'=>'control-label col-md-2']) !!}
<div class="col-md-10">
{!! Form::textarea('tekst', null, ['class'=>'form-control', 'placeholder'=>'Ovde upisite celu vest']) !!}
{!! $errors->has('tekst')?$errors->first('tekst'):'' !!}
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
{{ Form::label('upload_slike', 'Ubacite sliku:')}}
{{ Form::file('upload_slike') }}
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
{!! Form::submit('Sačuvaj', ['class'=>'btn btn-primary']) !!}
</div>
</div>
</div>
{!! Form::close() !!}
#stop
And this error

The error in the image shows that the error is occurring when you're opening a form tag to delete. Check line 5 in the screenshot you took.
Are you including a delete function on your create screen; perhaps in the extended view layouts.bez-sidebar? If you are then that could be why $blog->id is causing a trying to get property of non object error.

Related

QueryException error while updating data

Into database not update data, i can't understand my problem, error is below
Illuminate \ Database \ QueryException (42S22)
SQLSTATE[42S22]: Column not found: 1054 Unknown column '_method' in 'field list' (SQL: update trades set _method = PATCH, _token = AcbGEbEyNxX3e2RzRR2cb1SW6NDvkJuDqFevl0Mr, exchange_id = 1, market_id = 1, symbol_id = 45, is_action = 0, tradedate = , rate = 5000, note = hhhhhhhhh, updated_at = 2018-07-21 13:06:13 where trades.user_id = 33 and trades.user_id is not null and trades.deleted_at is null)
This is my controller
public function edit($id)
{
$trade = Trade::findOrFail($id);
$exchanges = Exchange::pluck('exchange','id')->all();
$markets = Market::pluck('market','id')->all();
$symbols = Symbol::pluck('symbol','id')->all();
$reasons = Reason::pluck('reason','id')->all();
return view('member.add-single-trade.edit', compact('trade','reasons', 'exchanges', 'markets', 'symbols'));
}
public function update(Request $request, $id)
{
$input = $request->all();
$tradeID= Auth::user()->trade($id)->update($input);
$reasons=$request->input('reason');
$data = [];
foreach($reasons as $key => $value) {
$data[] = ['reason_id' => $value];
};
$data = array(
'reason_id' =>$reasons,
'trade_id' => $tradeID->id,
);
$test['trade_id']= $tradeID->id;
if($data > 0) {
foreach ($data as $datum) {
$tradeID->tradereason()->update(new TradeReason($datum));
}
}
}
This is my edit.blade.php file
{!! Form::model($trade,['method'=>'PATCH', 'action'=> ['trades\AddSingleTradeController#update',$trade->id]]) !!}
<div class="col-sm-10">
<div class="form-group col-sm-5">
{!! Form::label('exchange_id', 'Exchanges:') !!}
{!! Form::select('exchange_id', [''=>'Choose Options'] + $exchanges , null, ['class'=>'form-control'])!!}
</div>
<div class="form-group col-sm-5">
{!! Form::label('market_id', 'Markets:') !!}
{!! Form::select('market_id', [''=>'Choose Options'] + $markets, null, ['class'=>'form-control'])!!}
</div>
<div class="form-group col-sm-10">
{!! Form::label('symbol_id', 'Symbols:') !!}
{!! Form::select('symbol_id', [''=>'Choose Options']+ $symbals , null, ['class'=>'form-control'])!!}
</div>
<div class="form-group col-sm-10">
{{ Form::radio('is_action', 1) }} Buy
{{ Form::radio('is_action', 0) }} Sell
</div>
<div class="form-group col-lg-5">
{!! Form::label('tradedate', 'Traded date:') !!}
{!! Form::date('tradedate', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group col-lg-5">
{!! Form::label('rate', 'Traded Rate:') !!}
{!! Form::text('rate', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group col-sm-10">
{!! Form::label('reason', 'Choose Reasons:') !!}
{{Form::select('reason',$reasons,null, array('id'=>'reasons','multiple'=>'multiple','name'=>'reason[]',"class"=>"js-example-basic-multiple form-control", 'data-width'=>'60%', 'data-live-search'=>'true','onchange' => 'all_function()'))}}
</div>
<div class="form-group col-lg-10">
{!! Form::label('note', 'Note:') !!}
{!! Form::textarea('note', null, ['class'=>'form-control', 'rows' => 2, 'cols' => 40])!!}
</div>
<div class="form-group col-lg-4">
{!! Form::submit('Save', ['class'=>'btn btn-success btn-lg']) !!}
</div>
{!! Form::close() !!}
<div class="form-group col-lg-4">
{!! Form::open(['method'=>'DELETE', 'action'=> ['trades\AddSingleTradeController#destroy', $trade->id]]) !!}
<div class="form-group">
{!! Form::submit('Delete', ['class'=>'btn btn-danger btn-lg']) !!}
</div>
</div>
{!! Form::close() !!}
This is my create.blade.php file
<td>{{$trade->stoploss}}</td>
You haven't included your model code (probably you are using $guarded = [];) but probably instead of
$input = $request->all();
you should use:
$input = $request->except('_method');
This is because additional _method field is added to form to pass HTTP verb method when using Form::model and obviously you don't have _method field in your table
EDIT
In case you have more fields you can include more fields to ignore for example:
$input = $request->except('_method', '_token');
or you can only use get fields you really want to get for example:
$input = $request->only('exchange_id', 'market_id');
(Of course you should add more fields to above - this is only example)
You can use $fillable property of the model to tell ORM which attributes (columns) can be mass assignable. Any other fields passed via update and create methods will be discarded. check at Laravel docs

Please what am I missing, Am using Laravel Framework

Property Controller
public function store(CreatePropertyRequest $request)
{
$property = Property::create($request->except(['_token', 'property_photo']));
if($request->hasFile('property_photos')) {
foreach($request->file('property_photos') as $photo) {
$imageName = Storage::disk('public')->putFile('propertyImages/' . $property->id, $photo);
PropertyPhoto::create(['property_id' => $property->id, 'filename' => $imageName]);
}
}
return redirect()->route('property.index');
}
Property Model
//I have set the fillable field
public function propertyPhotos()
{
return $this->hasMany(PropertyPhoto::class, 'property_id');
}
PropertyPhoto Model
class PropertyPhoto extends Model
{
//
protected $fillable = ['property_id', 'filename'];
public function property()
{
return $this->belongsTo(Property::class);
}
public function getFilenameAttribute()
{
return 'storage/propertyImages/'. $this->property_id. '/' . $this->filename;
}
}
AND VIEW PAGE
{!! Form::open(['method' => 'POST','action' => 'PropertyController#store', 'enctype' => 'multipart/form-data']) !!}
{!! csrf_field() !!}
<div class="form-body">
<!-- <h3 class="card-title m-t-15">Property Information</h3> -->
<h3 class="box-title m-t-40">Property Details</h3>
<hr>
<div class="row">
<div class="col-md-8">
<div class="form-group">
{!! Form::label('property_title', 'Property Title') !!}
{!! Form::text('property_title', null, ['class' => 'form-control'] ) !!}
</div>
</div>
<!--/span-->
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_category', 'Category' . '*') !!}
{!! Form::select('property_category', ['sale' => 'Sale', 'rent' => 'Rent', 'lease' => 'Lease'], null, ['class' => 'form-control', 'placeholder' => '--Choose Property Category--']) !!}
</div>
</div>
<!--/span-->
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_group', 'Property Group') !!}
{!! Form::select('property_group', $propertygroups, null, ['class' => 'form-control', 'placeholder' => 'Property Group' ]) !!}
</div>
</div>
<!--/span-->
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_type', 'Type') !!}
{!! Form::select('property_type', [], null, ['class' =>'form-control', 'placeholder' => '---Property Type---' ] ) !!}
</div>
</div>
<!--/span-->
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_location', 'Location') !!}
{!! Form::select('property_location', $locations, null, ['class' => 'form-control', 'placeholder' => 'Choose Location']) !!}
</div>
</div>
<!--/span-->
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_area', 'Area') !!}
{!! Form::select('property_area',[], null, ['class' => 'form-control', 'placeholder' => '---Select Area---']) !!}
</div>
</div>
<div class="col-md-8">
<div class="form-group">
{!! Form::label('property_busstop', 'Bus Stop') !!}
{!! Form::text('property_busstop', null, ['class' =>'form-control', 'placeholder' => 'Closest Bus Stop to Property']) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-8">
<div class="form-group">
{!! Form::label('property_address', 'Address') !!}
{!! Form::text('property_address', null, ['class' => 'form-control', 'placeholder' => 'Address of the Property' ]) !!}
</div>
</div>
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_postcode', 'Post Code') !!}
{!! Form::text('property_postcode', null, ['class' => 'form-control']) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_amount', 'Currency Type') !!}
{!! Form::select('property_amount',['n' => 'Naira Sign','s' => '$'], null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_amount', 'Amount') !!}
{!! Form::text('property_amount', null, ['class' => 'form-control' ]) !!}
</div>
</div>
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_size', 'Size') !!}
{!! Form::text('property_size', null, ['placeholder' => 'Property Size in sqr mtr','class' => 'form-control']) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_bedrooms', 'No. of Bedrooms') !!}
{!! Form::text('property_bedrooms', null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_bathrooms', 'No. of Bathrooms') !!}
{!! Form::text('property_bathrooms', null, ['class' => 'form-control' ]) !!}
</div>
</div>
<div class="col-md-4">
<div class="form-group">
{!! Form::label('property_toilet', 'No. of Toilet') !!}
{!! Form::text('property_toilet', null, ['class' => 'form-control']) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
{!! Form::label('property_carpack', 'No. of Car Pack') !!}
{!! Form::text('property_carpack', null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{!! Form::label('property_mode', 'Mode') !!}
{!! Form::select('property_mode',['fully_furnish' => 'Fully Furnish', 'partly_furnish' => 'Partly Furnish', 'unfurnish' => 'Unfurnish'], null, ['class' => 'form-control' ]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
{!! Form::label('property_social_medias', 'Social Media Link(s)') !!}
{!! Form::text('property_social_medias', null, ['class' => 'form-control']) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
{!! Form::label('property_facilities', 'Facilities') !!}
{!! Form::text('property_facilities', null, ['class' => 'form-control']) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
{!! Form::label('property_description', 'Description') !!}
{!! Form::textarea('property_description', null, ['class' => 'form-control','rows' => 3 ]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
{!! Form::label('property_photos', 'Property Photo') !!}
{!! Form::file('property_photos', array('class' => 'form-control', 'multiple')) !!}
</div>
</div>
</div>
</div>
<div class="form-actions">
{!! Form::submit('Submit', ['class' => 'btn btn-success'] ) !!}
Go Back
</div>
{!! Form::close() !!}
</div>
</div>
</div>
<!--Displa Error Message Here -->
#if(count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<!---------End------------------>
DATABASE MIGRATION
for propertyphotos
public function up()
{
Schema::create('property_photos', function (Blueprint $table) {
$table->increments('id');
$table->integer('property_id')->unsigned()->index();
$table->string('filename');
$table->timestamps();
$table->foreign('property_id')
->references('id')->on('properties')
->onDelete('cascade');
});
}
The problem is: When I click the submit button, the records are inserted into property table, and no record whatsover is inserted to propertyphotos table, nor is any path created for property_images, and worst is that there is no error message.
Also, in my {!! Form::open() !!} I included the 'files' => true
I did change it to 'encytype' => 'multipart/form-data' and no luck.
Please, what am I missing? Is there a better way to achieve what I am trying to do? Any suggestion whatsoever would be highly appreciated. Thanks.
Please make sure you are using enctype= "multipart/form-data" within form tag
A review of what you have
You have a form where you add a property and multiple photos. It would be super helpful to know how your html looks like, but i'll just assume your input for the file is and that you have ... and you have added a hidden input with csrf token and you also do some validation behind that request to make sure the files are always sent. I will also assume you don;t so this using ajax (which would change the behavior a bit)
In Property model you have a reltionshop with PropertyPhoto called property_photos (should be propertyPhotos) and is hasMany
In PropertyPhoto you have a relation with Property model and it's called propertis (shoudld be called property since is belongs to)
In PropertyController you have a method called store where you want to store all this stuff. This is how you should do it:
Code
In Property and PropertyPhoto model add the column you want to save to in fillable like this
In Property:
protected $fillable = [
'property_title',
'property_category',
'property_group',
'property_type',
'property_location',
'property_area',
'property_busstop',
'property_address',
'property_postcode',
'property_amount',
'property_size',
'property_bedrooms',
'property_bathrooms',
'property_toilet',
'property_carpack',
'property_mode',
'property_social_medias',
'property_facilities',
'property_description',];
In PropertyPhotos
protected $fillable = ['property_id', 'filename'];
This is not mandatory, but makes the code look a lot cleaner. You can skip this
public function store(Request $request)
{
$property = Property::create($request->except['_token', 'property_photos']);
if($request->hasFile('property_photos')) {
$images = [];
foreach($request->file('property_photos') as $photo) {
$imageName = Storage::disk('public')->putFile('propertyImages/' . $property->id, $photo);
$images[]['filename'] = $imageName;
}
$property->property_images()->create($images);
}
return redirect()->route('property.index');
}
or
public function store(Request $request)
{
$property = Property::create($request->except['_token', 'property_photos']);
if($request->hasFile('property_photos')) {
foreach($request->file('property_photos') as $photo) {
$imageName = Storage::disk('public')->putFile('propertyImages/' . $property->id, $photo);
PropertyImages::create(['property_id' => $property->id, 'filename' => $imageName]);
}
}
return redirect()->route('property.index');
}
in PropertyImages
This is an accessor used to get the path to the image
public function getFilenameAttribute()
{
// edit here: since filename should include that stuff. Image should be in storage/propertyImages/propertyId
return 'storage/' . $this->filename;
}
finally php artisan storge:link
You should save all your files in storage. Later if you work with AWS of GCloud you can use S3 or Bucket to store files at lower costs
To access the image $propertyImage->filename; // just like that

Several updates on the same view Laravel

In a setup process I want to:
select langs of the application (1 or more) ...
Update the DB
Select the default language
Update again the DB...
For this i created 3 routes.
Route::get('/home/setup', 'BackOffice\FirstconnectionController#initLang');
Route::patch('/home/setup', 'BackOffice\FirstconnectionController#initLangUpdate')->name('setup.setLang');
Route::patch('/home/setup', 'BackOffice\FirstconnectionController#setDefaultLang')->name('setup.setDefaultLang');
The first is the home page where i make eloquent requests
The second route display the list of languages
The third route displays the list of languages which are published ...
Here is my view :
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif
{{-- IF NO LANGS ARE PUBLISHED I CAN CHOOSE HERE --}}
#if ($langsCount == 0)
{!! Form::model($langs, [
'method' => 'PATCH',
'route' => 'setup.setLang'
])
!!}
#foreach($langs as $lang)
<div class="form-group">
{{--<label class="col-md-4"> {{ $lang->langname }} </label>--}}
{{--<input id="{{ $lang->langisocode }}" type="checkbox">--}}
{!! Form::label($lang->langname, $lang->langname ) !!}
{!! Form::checkbox( 'lang[]', $lang->id ) !!}
</div>
#endforeach
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Valider</button>
</div>
{!! Form::close() !!}
{{-- NOW I SELECT DEFAULT LANGUAGE... --}}
#else
{!! Form::model($langs, [
'method' => 'PATCH',
'route' => 'setup.setDefaultLang'
])
!!}
#foreach($pubLangs as $pubLang)
{!! Form::label($pubLang->langname, $pubLang->langname ) !!}
{!! Form::radio( 'lang', $pubLang->id ) !!}
<br>
#endforeach
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Valider</button>
</div>
{!! Form::close() !!}
#endif
Here is my controller :
// I display the info here
public function initLang()
{
$langs = Lang::onlyTrashed()->get();
$langsCount = Lang::count();
$pubLangs = Lang::all();
return view('admin.firstConnection', compact('langs', 'langsCount', 'pubLangs'));
}
public function initLangUpdate(Request $request) {
$request = $request->input('lang');
foreach ($request as $entry) {
Lang::withTrashed()->find($entry)->restore();
}
return redirect('admin/home/setup')->with('success', 'OK');
}
public function setDefaultLang(Request $request) {
$request = $request->input('lang');
return $request;
}
I will update the setDefaultLang after ...
I have this error message :
Route [setup.setLang] not defined

laravel how to use star rating plugin on a form text input

My project is on storing reviews on products. I am using Laravel framework here. The review has a field for rating the product. I am using the jquery 'starrr' plugin for the rating.
Form :
{!! Form::open(['url'=>'/admin/reviews', 'role' => 'form', 'class' => 'form-horizontal']) !!}
<div class="form-group">
{!! Form::label('title', "Title:", ['class'=>'control-label col-md-2']) !!}
<div class="col-md-8">
{!! Form::text('title', null, ['class'=>'form-control'])!!}
</div>
</div>
<div class="form-group">
{!! Form::label('product_id', "Product:", ['class'=>'control-label col-md-2']) !!}
<div class="col-md-8">
{!! Form::select('product_id', $products, null, ['class'=>'form-control product_list'])!!}
</div>
</div>
<div class="form-group">
{!! Form::label('rating', "Rating:", ['class'=>'control-label col-md-2']) !!}
<div class="starrr"></div>
{!! Form::hidden('rating', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
<div class="col-md-3 col-md-offset-4">
{!! Form::button('<i class = "fa fa-plus-circle"></i> Add New Review', ['type' => 'submit', 'class'=>'btn btn-primary btn-lg']) !!}
</div>
</div>
{!! Form::close() !!}
controller store method:
public function store(Request $request){
$rules = [
'product_id' => 'required',
'title' => 'required',
'content' => 'required',
];
$this->validate($request, $rules);
create($request->all());
return redirect('admin/reviews')->withSuccess('Review is created');
}
My question is how to get the rating value from the star rating, into the request object to store on the database?
Thanks for your help in advance
$('.starrr').starrr({
change: function(e, value){
$('input[name="value"]').val(value)
}
})
This will set the input to the value of the starrr plugin whenever it is changed. Then the input value will be sent to the server

Laravel 5 MethodNotAllowedHttpException issues

I am trying to make a simple CRUD for Clients. At the moment I can view clients and get to the edit page. However, if I try to update or create a client, I get a MethodNotAllowedHttpException.
My routes look like the following
Route::model('clients', 'Client');
Route::bind('clients', function($value, $route) {
return App\Client::whereSlug($value)->first();
});
Route::resource('clients', 'ClientsController');
My controller is like so
<?php
namespace App\Http\Controllers;
use App\Client;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Input;
use Redirect;
use Illuminate\Http\Request;
class ClientsController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
$clients = Client::all();
return view('clients.index', compact('clients'));
}
/**
* Show the form for creating a new resource.
*
* #return Response
*/
public function create()
{
return view('clients.create');
}
/**
* Store a newly created resource in storage.
*
* #return Response
*/
public function store()
{
$input = Input::all();
Client::create( $input );
return Redirect::route('clients.index')->with('message', 'Client created');
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Client $client
* #return Response
*/
public function edit(Client $client)
{
return view('clients.edit', compact('client'));
}
/**
* Update the specified resource in storage.
*
* #param \App\Client $client
* #return Response
*/
public function update(Client $client)
{
$input = array_except(Input::all(), '_method');
$client->update($input);
return Redirect::route('clients.index', $client->slug)->with('message', 'Client updated.');
}
/**
* Remove the specified resource from storage.
*
* #param \App\Client $client
* #return Response
*/
public function destroy(Client $client)
{
$client->delete();
return Redirect::route('clients.index')->with('message', 'Client deleted.');
}
}
I then have a form partial like so
<div class="form-group">
{!! Form::label('clientName', 'Client Name:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('clientName', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('contactEmail', 'Contact Email:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('contactEmail', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('slug', 'Slug:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('slug', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::submit($submit_text, ['class'=>'btn btn-default']) !!}
</div>
And my edit.blade.php is like so
<h2>Edit Client</h2>
{!! Form::model($client, ['class'=>'form-horizontal'], ['method' => 'PATCH', 'route' => ['clients.update', $client->slug]]) !!}
#include('clients/partials/_form', ['submit_text' => 'Edit Client'])
{!! Form::close() !!}
I have researched this error and a lot of people refer to javascript, but I am not using any javascript at the moment.
Why would I be getting this error? As I say, I get it when I try to create a client as well.
Thanks
As an update, if I remove the form partial and add this to ed.it.blade.php instead, it seems to work
{!! Form::model($client, [
'method' => 'PATCH',
'route' => ['clients.update', $client->slug]
]) !!}
<div class="form-group">
{!! Form::label('clientName', 'Client Name:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('clientName', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('contactEmail', 'Contact Email:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('contactEmail', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('slug', 'Slug:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('slug', null, array('class' => 'form-control')) !!}
</div>
</div>
{!! Form::submit('Update Client', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
Why is that?

Resources