Laravel delete button not working - laravel-5

I was wondering if someone can look at this code and tell me why it's not working. When I press the submit button, it will not submit.
{!! Form::open([
'method' => 'DELETE',
'route' => ['posts.destroy', $post->id],
'style' => 'display: inline'
]) !!}
{!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
I'm submitting it to a PostController's destory method, where the route is defined as 'posts'.
Route file
Route::group(['prefix' => 'admin'], function() {
Route::resource('posts', 'PostController');
});

Change
{!! Form::open([
'method' => 'DELETE',
'route' => ['posts.destroy', $post->id],
'style' => 'display: inline'
]) !!}
{!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
To
{!! Form::open([
'method' => 'DELETE',
'route' => ['admin.posts.destroy', $post->id],
'style' => 'display: inline'
]) !!}
{!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
Following your prefix in route. Hope it would help

Related

how to pass multiple parameters through route using Laravel collective Forms & HTML Addins?

lets assume we have a Delete button inside a form :
{!! Form::open(['route' => ['posts.destroy','id'=>$post->id], 'method' => 'delete']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
i need to pass two or more variables through the Form Route like this:
{!! Form::open(['route' => ['posts.destroy','id'=>$post->id,'title'=>$post->title], 'method' => 'delete']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
I try to different ways , to take these two parameters but still I couldn't retrieve data
ErrorException in PostController.php line 99:
Missing argument 2 for App\Http\Controllers\PostController::destroy()

Add input field into modal box by Collective

This code make below modal.
How can I add input field to this modal by Blade?
{!! Form::open(['route' => ['jobs.destroy', $job->id], 'method' => 'delete', 'class' => 'btn-group', 'id' => 'jobStop']) !!}
{!! Form::button('<i class="glyphicon glyphicon-stop"></i>', ['type' => 'submit', 'class' => 'btn btn-warning btn-xs', 'onclick' => "return confirm('Are you sure you want stop?')"]) !!}
{!! Form::close() !!}

UrlGenerationException: Missing required parameters for [Route: topics.update] [URI: topics/{topic}]

I'm getting this error:
Missing required parameters for [Route: topics.update] [URI: topics/{topic}]. (View: C:\xampp\htdocs\phpboards\resources\views\topics\edit.blade.php)
This is link that will take user to edit:
Edit
This is the controller for edit:
$topic = Topic::find($id);
return view('topics.edit')->with('topic', $topic);
This is the Route:
Route::get('/boards/topics/edit/{id}', 'TopicController#edit');
This is the form for edit:
<div class="container">
{!! Form::open(['action' => 'TopicController#update', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('title', 'Title') }}
{{ Form::text('title', $topic->topic_title, ['class' => 'form-control', 'placeholder' => 'Title of the Post']) }}
</div>
<div class="form-group">
{{ Form::label('desc', 'Desc') }}
{{ Form::textarea('desc', $topic->topic_body, ['class' => 'form-control', 'placeholder' => 'Description of the Post']) }}
</div>
{{ Form::submit('Submit', ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
</div>
What i have done wrong here??
Instead of:
{!! Form::open(['action' => 'TopicController#update', 'method' => 'POST']) !!}
use
{!! Form::open(['url' => route('topics.update', $topic->id), 'method' => 'POST']) !!}
because for your route you need to pass id of topic you want to update. Also it's more reasonable to use named routes instead Controller#method notation.
Let's admit your update() method is already implemented on your TopicController.
First you need to declare another route:
Route::put('/boards/topics/edit/{id}', 'TopicController#update');
// ^^^
then change your Form opening by this:
{!! Form::open(['action' => ['TopicController#update', $topic->id], 'method' => 'put']) !!}
// ^^^^^^^^^^ ^^^
it should works.

I am getting error message

Getting error : syntax error, unexpected '=>' (T_DOUBLE_ARROW)
my code is :
#extends('layouts.masters.main')
#section('page-content')
<div class="container">
#include('layouts.partials.nav')
{!! Form::open(['route' => 'post_register', 'id' => 'registration-form']) !!}
{!! Form::label('name', 'Full Name') !!}
{!! Form::text('name', null, ['id' => 'name', 'class' => 'form-control', 'placeholder' => 'Full Name', 'required']) !!}
{!! Form::label('email', 'Email Address') !!}
{!! Form::email('email',null,['id' => 'email', 'class' => 'form-control', 'placeholder' => 'Email Address', 'required']) !!}
{!! Form::label('password', 'password') !!}
{!! Form::password('password',['id' => 'password', 'class' => 'form-control', 'placeholder' => 'password', 'required']) !!}
{!! Form::button('Register','class' => 'btn btn-lg btn-primary btn-block', 'type' => 'submit')!!}
{!! Form::close() !!}
</div> <!-- /container -->
#stop
please help ... i can't uderstand where i do the mistake in this code
When you use "=>" the content should be inside an array (class, type, etc..)
So, try this;
{!! Form::button('Register', ['class' => 'btn btn-lg btn-primary btn-block', 'type' => 'submit']) !!}

Method is not allowed

I am trying to create simple form with post. But when i submit my form i get this error - MethodNotAllowedHttpException in RouteCollection.php line 219:
My route file:
Route::get('articles', 'ArticlesController#index');
Route::get('articles/create', 'ArticlesController#create');
Route::get('articles/{id}', 'ArticlesController#show');
Route::post('articles', 'ArticlesController#store');
Form:
{!! Form::open(['url' => 'articles', 'method' => 'post']) !!}
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('body', 'Body:') !!}
{!! Form::textarea('body', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Add article', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
Controller class:
public function store(Request $request) {
$input = $request->all();
return $input;
}
Thanks for your attention. I dont get where is the problem.
Found answer. Just type php artisan route:clear in terminal.
You have the same url both in Route::get('articles', 'ArticlesController#index'); and Route::post('articles', 'ArticlesController#store');
Use action() instead of url can solve this problem. EX:
{!! Form::open(['action' => 'ArticlesController#store', 'method' => 'post']) !!}
Change the route: Route::get('articles', 'ArticlesController#index'); to Route::post('articles', 'ArticlesController#index');

Resources