I just added it in my first post. But (when I call it with 'http://localhost:8000/cats/1/delete') code execution never enters in CatController.php (I mean the code in CatController.php is not executed, it doesn't even enter in the code of CatController.php). While when other routes are called, code execution goes normally. (I check this with netBeans)
i really wont work. you need to use DELETE method for it to fire.
<form action={{ route('cats.destroy', [$somecat->id]) method="post">
<input type="hidden" name="_method" value="DELETE">
</form>
//or override the route.
Route::get('cats/{cats}/delete', ['as' => 'cats.destroy', 'uses' =>'CatController@destroy']);
//this will now work. http://localhost:8000/cats/1/delete
This is my view/cats/edit.blade.php:
<html>
@extends('master')
@section('header')
<a href="{{ URL::route('cats.show', $cat->id) }}">Cancel</a>
<h2>
@if($method == 'post')
Add a new cat
@elseif($method == 'delete')
Delete {{$cat->name}}?
@else
Edit {{$cat->name}}
@endif
</h2>
@stop
@section('content')
{{Form::model($cat, array('method' => $method, 'url'=>'cats/'.$cat->id))}}
@unless($method == 'delete')
<div class="form-group">
{{Form::label('Name')}}
{{Form::text('name')}}
</div>
<div class="form-group">
{{Form::label('Date of birth')}}
{{Form::text('date_of_birth')}}
</div>
<div class="form-group">
{{Form::label('Breed')}}
{{Form::select('breed_id', $breed_options)}}
</div>
{{Form::submit("Save", array("class"=>"btn btn-default"))}}
@else
{{Form::submit("Delete", array("class"=>"btn btn-default"))}}
@endif
{{Form::close()}}
@stop
</html>
How can I adjust this? (which is PHP):
<form action={{ route('cats.destroy', [$somecat->id]) method="post">
<input type="hidden" name="_method" value="DELETE">
</form>
so that it 'll work in my edit.blade.php?
Try something like this
{{ Form::open(array('method' => 'Delete', 'route' => array('cats.destroy', $cat->id), 'class' => 'delete-form')) }}
<button class="btn btn-danger"><i class="fa fa-pencil"></i> Delete</button>
{{ Form::close() }}
I changed my edit.blade.php to:
<html>
@extends('master')
@section('header')
<a href="{{ URL::route('cats.show', $cat->id) }}">Cancel</a>
<h2>
@if($method == 'post')
Add a new cat
@elseif($method == 'delete')
Delete {{$cat->name}}?
@else
Edit {{$cat->name}}
@endif
</h2>
@stop
@section('content')
{{ Form::open(array('method' => 'Delete', 'route' => array('cats.destroy', $cat->id), 'class' => 'delete-form')) }}
<button class="btn btn-danger"><i class="fa fa-pencil"></i> Delete</button>
{{ Form::close() }}
@stop
</html>
It doesn't work, it gives me the same error, ;page not found'.
Ok, this one works if I firstly click 'Edit' and then the new added delete button:
{{Form::model($cat, array('method' => $method, 'url'=>'cats/'.$cat->id))}}
@unless($method == 'delete')
<div class="form-group">
{{Form::label('Name')}}
{{Form::text('name')}}
</div>
<div class="form-group">
{{Form::label('Date of birth')}}
{{Form::text('date_of_birth')}}
</div>
<div class="form-group">
{{Form::label('Breed')}}
{{Form::select('breed_id', $breed_options)}}
</div>
{{Form::submit("Save", array("class"=>"btn btn-default"))}}
@else
@endif
{{Form::close()}}
{{ Form::open(array('method' => 'Delete', 'route' => array('cats.destroy', $cat->id), 'class' => 'delete-form')) }}
<button class="btn btn-danger"><i class="fa fa-pencil"></i> Delete</button>
{{ Form::close() }}
I guess I 'll have to adopt the code to work as I want.Thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community