title: Index.blade.php could not find Routes to Posts.destroy
body: <p>I was trying to link my posts.delete to my index.blade.php but I keep getting Symfony\Component\Routing\Exception\RouteNotFoundException</p>
  <p>index.blade.php</p>
  <pre><code>@extends('layouts.app')
  
  @section('content')
  
      &lt;div class=&quot;flex justify-center&quot;&gt;
          &lt;div class=&quot;w-8/12 bg-white p-6 rounded-lg&quot;&gt;
              &lt;form action=&quot;{{ route('posts') }}&quot; method=&quot;post&quot; class=&quot;mb-4&quot;&gt;
                  @csrf
                  &lt;div class=&quot;mb-4&quot;&gt;
                      &lt;label for=&quot;body&quot; class=&quot;sr-only&quot;&gt;Body&lt;/label&gt;
                      &lt;textarea name=&quot;body&quot; id=&quot;body&quot; cols=&quot;30&quot; rows=&quot;4&quot; class=&quot;by-gray-100 border-2
                      w-full p-4 rounded lg @error('body') border-red-500 @enderror&quot; placeholder=&quot;Post something!&quot;&gt;&lt;/textarea&gt;
                      @error('body')
                          &lt;div class=&quot;text-red-500 mt-3 text-sm&quot;&gt;
                              {{$message}}
                          &lt;/div&gt;
                      @enderror
                  &lt;/div&gt;
                  &lt;div&gt;
                      &lt;button type=&quot;submit&quot; class=&quot;bg-blue-500 text-white px-4 py-2 rounded
                      font-medium&quot;&gt;Post&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
              @if ($posts-&gt;count())
                  @foreach ($posts as $post)
                      &lt;div class=&quot;mb-4&quot;&gt;
                          &lt;a href=&quot;&quot; class=&quot;font-bold&quot;&gt;{{ $post-&gt;user-&gt;username }}&lt;/a&gt;
                          &lt;span class=&quot;text-gray-600 text-sm&quot;&gt;{{ $post-&gt;created_at-&gt;diffForHumans() }}&lt;/span&gt;
                          &lt;p class=&quot;mb-2&quot;&gt;{{ $post-&gt;body }}&lt;/p&gt;
  
                          &lt;div class=&quot;flex items-center&quot;&gt;
                              @if (!$post-&gt;likedBy(auth()-&gt;user()))
                                  &lt;form action=&quot;{{ route('posts.likes', $post) }}&quot; method=&quot;post&quot; class=&quot;mr-1&quot;&gt;
                                      @csrf
                                      &lt;button type=&quot;submit&quot; class=&quot;text-blue-500&quot;&gt;Like&lt;/button&gt;
                                  &lt;/form&gt;
                              @else
                                  &lt;form action=&quot;{{ route('posts.destroy', $post) }}&quot; method=&quot;delete&quot; class=&quot;mr-1&quot;&gt;
                                      @csrf
                                      @method('DELETE')
                                      &lt;button type=&quot;submit&quot; class=&quot;text-blue-500&quot;&gt;Unlike&lt;/button&gt;
                                  &lt;/form&gt;
  
                              @endif
                              &lt;span&gt;{{ $post-&gt;likes-&gt;count() }} {{ Str::plural('likes', $post-&gt;likes-&gt;count()) }}&lt;/span&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                  @endforeach
  
                  {{ $posts-&gt;links() }}
  
              @else
                  There are no posts...
              @endif
          &lt;/div&gt;
      &lt;/div&gt;
  
  @endsection
  </code></pre>
  <p>PostLikeController</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Models\Post;
  use Illuminate\Http\Request;
  
  class PostLikeController extends Controller
  {
      public function __construct()
      {
          $this-&gt;middleware(['auth']);
      }
  
      public function store(Post $post, Request $request)
      //While trying to add $request here it gave back an Undefined variable '$request'.
      //But after adding Request $request to it, it worked...
      {
          if ($post-&gt;likedBy($request-&gt;user())){
              return response(null, 409);
          }
          $post-&gt;likes()-&gt;create([
              'user_id' =&gt; $request-&gt;user()-&gt;id,
          ]);
  
          return back();
      }
  
      public function destroy(Post $post, Request $request)
      {
          dd($post);
      }
  
  }
  </code></pre>
  <p>web.php</p>
  <pre><code>&lt;?php
  
  use Illuminate\Support\Facades\Route;
  use App\Http\Controllers\PostController;
  use App\Http\Controllers\PostLikeController;
  use App\Http\Controllers\DashboardController;
  use App\Http\Controllers\Auth\LoginController;
  use App\Http\Controllers\Auth\LogoutController;
  use App\Http\Controllers\Auth\RegisterController;
  
  /*
  |--------------------------------------------------------------------------
  | Web Routes
  |--------------------------------------------------------------------------
  |
  | Here is where you can register web routes for your application. These
  | routes are loaded by the RouteServiceProvider within a group which
  | contains the &quot;web&quot; middleware group. Now create something great!
  |
  */
  
  Route::get('/', function () {
      //return view('welcome');
  });
  
  // Route::get('/', function () {
  //     return view('posts.index');
  // });
  
  Route::get('/', function () {
      return view('home');
  })-&gt;name('home');
  
  Route::get('/dashboard', [DashboardController::class, 'index'] )
  -&gt;name('dashboard')
  -&gt;middleware('auth');
  
  Route::get('/register', [RegisterController::class, 'index'] )-&gt;name('register');
  Route::post('/register', [RegisterController::class, 'store'] );
  
  Route::get('/login', [LoginController::class, 'index'] )-&gt;name('login');
  Route::post('/login', [LoginController::class, 'store'] );
  
  Route::post('/logout', [LogoutController::class, 'store'] )-&gt;name('logout');
  
  Route::get('/login', [LoginController::class, 'index'] )-&gt;name('login');
  
  Route::get('/posts', [PostController::class, 'index'] )-&gt;name('posts');
  Route::post('/posts', [PostController::class, 'store'] );
  
  Route::post('/posts/{post}/likes', [PostLikeController::class, 'store'] )-&gt;name('posts.likes');
  Route::delete('/posts/{post}/likes', [PostLikeController::class, 'destroy'])-&gt;name('posts.likes');
  </code></pre>
  <p>Like.php</p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class Like extends Model
  {
      use HasFactory;
  
      protected $fillable = [
          'user_id'
      ];
  }
  </code></pre>
  <p>I checked my routes:list and I found that it was there</p>
  <p>+--------+----------+--------------------+-------------+----------------------------------------------------+------------+
  | Domain | Method   | URI                | Name        | Action<br />
  | Middleware |
  +--------+----------+--------------------+-------------+----------------------------------------------------+------------+
  |        | GET|HEAD | /                  | home        | Closure<br />
  | web        |
  |        | GET|HEAD | api/user           |             | Closure<br />
  | api        |
  |        |          |                    |             |
  | auth:api   |
  |        | GET|HEAD | dashboard          | dashboard   | App\Http\Controllers\DashboardController@index     | web        |
  |        |          |                    |             |
  | auth       |
  |        | GET|HEAD | login              | login       | App\Http\Controllers\Auth\LoginController@index    | web        |
  |        |          |                    |             |
  | guest      |
  |        | POST     | login              |             | App\Http\Controllers\Auth\LoginController@store    | web        |
  |        |          |                    |             |
  | guest      |
  |        | POST     | logout             | logout      | App\Http\Controllers\Auth\LogoutController@store   | web        |
  |        | GET|HEAD | posts              | posts       | App\Http\Controllers\PostController@index          | web        |
  |        | POST     | posts              |             | App\Http\Controllers\PostController@store          | web        |
  |        | POST     | posts/{post}/likes | posts.likes | App\Http\Controllers\PostLikeController@store      | web        |
  |        |          |                    |             |
  | auth       |
  |        | DELETE   | posts/{post}/likes | posts.likes | <strong>App\Http\Controllers\PostLikeController@destroy</strong>    | web        |
  |        |          |                    |             |
  | auth       |
  |        | GET|HEAD | register           | register    | App\Http\Controllers\Auth\RegisterController@index | web        |<br />
  |        |          |                    |             |                                                    | guest      |<br />
  |        | POST     | register           |             | App\Http\Controllers\Auth\RegisterController@store | web        |<br />
  |        |          |                    |             |                                                    | guest      |<br />
  +--------+----------+--------------------+-------------+----------------------------------------------------+------------+</p>
  <p><strong>N.B:</strong> I was trying to make it destroy the Likes that has been created but it keeps giving
  Symfony\Component\Routing\Exception\RouteNotFoundException
  Route [posts.destroy] not defined. (View: C:\xampp\htdocs\posty\resources\views\posts\index.blade.php)</p>