I'm trying to use #cannot in my template but I have the following issue. With the code:
#section('content')
#can('upload-images',$flyer)
<form action="{{ URL::to('/') }}/{{ $flyer->zip }}/{{ $flyer->street }}/photos" method="POST" class="dropzone" enctype="multipart/form-data">
{{ csrf_field() }}
</form>
#endcan
#cannot
<p>Not allowed</p>
#endcannot
#stop
#cannot throws the following error:
Undefined class constant 'denies'
I know #cannot exists and also that uses Gate::denies, which is the error I'm taking, here is the Github commit where the magic should occur:
https://github.com/laravel/framework/commit/9c41aa0d53412e3008285e89ff9764fa51b42469
Any clues? Thanks!
Laravel's doc has being updated. I should use #else:
#can(...)
#else
#endcan
And #cannot should be used as the opposite of #can, but never at the same time:
#cannot(...)
#else
#endcannot
You forgot the input in the cannot method:
#cannot('upload-images',$flyer)
<p>Not allowed</p>
#endcannot
However in this situation its more elegant to use else
#can('upload-images',$flyer)
<form action="{{ URL::to('/') }}/{{ $flyer->zip }}/{{ $flyer->street }}/photos" method="POST" class="dropzone" enctype="multipart/form-data">
{{ csrf_field() }}
</form>
#else
<p>Not allowed</p>
#endcan
Related
I try to delete some of my post with slug but it's not found.
My route:
Route::resource('/dashboard/berita', DashboardController::class)->parameters([
'berita' => 'post:slug'
])->middleware('auth');
My Controller:
public function destroy(Post $post) {
$post->delete();
return redirect('/dashboard/berita')->with('success', 'Berita sudah dihapus!');
}
My blade:
<form action="{/dashboard/berita/{{ $post->slug }}}" method="post" class="d-inline">
#method('delete')
#csrf
<button class="badge bg-danger border-0"> </button>
</form>
Your formatting is wrong, it should be
action="/dashboard/berita/{{ $post->slug }}"
Or better still, use a named route.
<form action="{{ route('post.destroy', $post )}}" >
The problem is with this section of your code: action="{/dashboard/berita/{{ $post->slug }}}"
you need to change it as below:
<form action="{{ url('/dashboard/berita/' . $post->slug) }}" method="post" class="d-inline">
</form>
Undefined variable: token (View:
C:\xampp\htdocs\blog\resources\views\auth\passwords\email.blade.php)
If you have used default auth(using php artisan make:auth) in laravel then change like this in \auth\passwords\email.blade.php file:
<form method="POST" action="{{ route('password.email') }}">
#csrf
In the form you don't need to add $token, you are already using it in the form. So your form action should be
action="{{ route('password.request') }}"
Also for csrf you can make input in the form by using following
{{ csrf_field() }}
Hello I had same issue with my #laravel6 project where i was trying to call same method and view from different URL.
I simply removed the second line after #csrf like this
<input type="hidden" name="token" value="{{ $token }}">
I removed this and its works fine.
and about token there is a token from #csrf so everything works as it is.
You just don't need to add $token manually in the form, you can just use csrf_field() inside the form and it'll generate the hidden field with csrf token
Your code should be like this
<form method="POST" action="{{ route('password.request') }}">
{{ csrf_field() }}
.
.
.
</form>
this is my view page route
<form method='post' action={{ route('shortlist.update', ['id' => $dd->jobseekers_unique_id, 'jid' => $dd->job_unique_id ]) }}>
{{ csrf_field() }} {{ method_field('PATCH') }}
<button type='submit' class="col-md-5 col-sm-5 btn btn-success">Shortlist</button>
</form>
and this my main route
Route::patch('shortlistt/{id}/{jid}','RecruiterController#shortlisted')->name('shortlist.update');
But it's giving me the error and I don't know how to make it work.
You have syntax error in your code, you missed the quotes for action. Here is your updated code.
<form method='post' action="{{ route('shortlist.update', ['id' =>
$dd->jobseekers_unique_id, 'jid' => $dd->job_unique_id ]) }}">
{{ csrf_field() }} {{ method_field('PATCH') }}
<button type='submit' class="col-md-5 col-sm-5 btn btn-success">Shortlist</button>
</form>
Hope it helps.
I have my website hosted. Not local. I am sending the email below.
#component('mail::message')
<form method="POST" action="/users/user/confirm/{{ $user->confirm_token }}">
{{ csrf_field() }}
{{ method_field('PATCH') }}
<button>Confirm</button>
</form>
Thanks,<br>
{{ config('app.name') }}
#endcomponent
When I get the email. I checked the form url. The url to the action is not correct. it is suppose to be https://mywebsite.com/users/user/confirm/234893h423d
this is how the form looks like in the email
-
<form method="POST" action="http:///users/user/confirm/234893h423d"
</form>
Use url() helper method:
<form method="POST" action="{{url('/users/user/confirm')}}/{{$user->confirm_token }}">
You should try this way:
<form method="POST" action="{{ url('users/user/confirm', $user->confirm_token) }}">
Do not delete that line of mysql. What is the problem ? D
Controller
public function destroy($id) {
$seriale = Serial::find($id);
$seriale->delete();
return redirect()->route('admin.seriale.index');
}
View
<form action="{{ route('admin.seriale.destroy',$seriale->id) }}" method="DELETE" role="form">
<button type="submit" class="btn btn-danger">Sterge Serial</button>
</form>
Fix Your form with this notation.
This helper adds special hidden fields to implement DELETE request.
{{ Form::open(['method' => 'DELETE', 'route' => ['admin.seriale.destroy', $seriale->id] ]) }}
<button type="submit" class="btn btn-danger">Sterge Serial</button>
{{ Form::close() }}
Read this question and answers: https://laracasts.com/index.php/discuss/channels/general-discussion/how-to-updatedelete-using-forms-and-restful-controllers?page=1
You can not send DELETE requests easily. Browsers only understand GET and POST. You have to use a magic field to tell Laravel that this is a DELETE request:
<form action="{{ route('admin.seriale.destroy',$seriale->id) }}" method="POST" role="form">
{{ csrf_field() }}
<!-- <input type="hidden" name="_method" value="DELETE"> -->
{{ method_field('delete') }} <!-- helper functions in laravel are awesome -->
<button type="submit" class="btn btn-danger">Sterge Serial</button>
</form>
I also added the csrf field to the form, you might need it.