error 419 but i am passing the token

Posted 6 months ago by marioeid

when i click delete it gives me error 419 still don't know why but it doesn't work my routes


Route::get('/', '[email protected]');
Route::get('/blog', '[email protected]');
Auth::routes();
Route::get('/home', '[email protected]')->name('home');
Route::get('ajax', function(){ return view('ajax'); });
Route::post('/postajax','[email protected]');
Route::post('/createpost','[email protected]');
Route::delete('/deletepost/{id}',['uses'=>'[email protected]','as'=>'post.delete','middleware'=>'auth']);

my view

  <ul id="posts" class="row">
                 @foreach($posts as $post)
                
                    <li class="arrow_box col-md-10 col-lg-10 offset-lg-2">
                    <p><span id="title">{{$post->title}}</span>
                    
                    <br/>
               <span id="body">{{$post->body}}</span>
                                   <br/>
                    <div class="info">
                    <p> 
                   <div id="funform">
                   <meta name="csrf-token" content="{{ csrf_token() }}">

                  <a  class="fa fa-trash post_delete" data-id="{{$post->id}}" data-url="/deletepost/{{$post->id}}"></a>
                   <a class="fa fa-thumbs-up post_like"></a>
                   <a class="fa fa-comment post_comment"></a>
                   <a class="fa fa-edit post_edit" </a></a>
                   </div> 
                   </p>
                   </div>
                    
                    </p>
                    
                    </li>
                @endforeach
                
            </ul>

my ajax note: there's only one class called post_delete in my view

 $('.post_delete').on('click',function(e)
    {
        e.preventDefault();
         var id = $(this).data("id");
         var url=$(this).data("url");
         var th=$(this).parent().parent().parent();    
        $.ajax({
            url:url,
            type: 'DELETE',
            data: {  "_token": "{{ csrf_token() }}"},
            dataType: 'JSON',
            success:function(data)
            {
               th.remove();
            },
        });
    }

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.