Support the ongoing development of Laravel.io →
posted 9 years ago
Input
Last updated 2 years ago.
0

What is your code?

0

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)

Last updated 9 years ago.
0

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
0

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?

0
Solution

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() }}
0

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'.

0

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!

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

panosss panosss Joined 18 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.