Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

voilatech's avatar

Can't see a route when using artisan command => route:list

Hello, I came across an issue where below route dose not appear in the route:list! any thought!?

<?php

Route::delete('/{id}', 'Subscription\SubscriptionController@destroy')->name('delete.subscription');

?>
0 likes
27 replies
Cronix's avatar

show your route file, and identify the one that isn't showing up when you do php artisan route:list

Cronix's avatar

Strange, it showed up for me when I put it in my routes...as the very last route. That's not a very good way to have it, imo... it would be better to have it be more specific like /subscription/{id}

bobbybouwmann's avatar

More specific would be better in all cases! The routes file is the first step of your application ;)

What file is your routes file?

Cronix's avatar

It's also better to not have ending php tags in your php files. It can cause issues and goes against the PSR standards for code, which laravel uses.

?>

remove that from all of your files. Even a space character after that end tag could cause your code to not run.

https://www.php-fig.org/psr/psr-2/

From 2.2:

The closing ?> tag MUST be omitted from files containing only PHP.

voilatech's avatar

Very Strange ! Now it shows up in the list! although I edited the URI...

Now , If I attempt to unsubscribe, I get undefined variable ! The controller :

 $unsubscription = Subscription::find($id);
        $unsubscription->delete();

        Session::flash('unsubscription', 'You have successfully unsubscribed from Our site!' );

        return redirect('/');

The view :

  {!! Form::open(['route' => ['delete.subscription', $unsubscription->id], 'method' => 'DELETE']) !!}

    {{Form::submit('Unsubscribe', ['class' => 'btn btn-danger btn-block' ]) }}

    {!! Form::close()!!}

Should mention that the view is the email when users subscribe it gets fired off!

voilatech's avatar

@Cronix agree! above snippetcode is just a demonstration! Laravel follows this ..

Cronix's avatar

show your new route, along with the whole controller method (including the method declaration)

voilatech's avatar

The new route:

Route::delete('/subscription/{id}', 'Subscription\SubscriptionController@destroy')->name('delete.subscription');

The method :

 public function destroy($id)
    {
        $unsubscription = Subscription::find($id);
        $unsubscription->delete();

        Session::flash('unsubscription', 'You have successfully unsubscribed from Our site!' );

        return redirect('/');
    }


Cronix's avatar

Now , If I attempt to unsubscribe, I get undefined variable

what variable?

Have you tried running php artisan view:clear and composer dumpautoload?

Should mention that the view is the email when users subscribe it gets fired off!

You mean that form is in the email being sent? Is the route in an auth route group or something so they have to be signed in first to be able to delete the subscription?

voilatech's avatar

previsuly , I declared in show method :

 public function show($id)
    {
        $unsubscribe = Subscription::find($id);

        return view('unsubscribe')->withInfo($unsubscribe);
    }

with below route :

Route::get('/unsubscription/{id}', 'Subscription\SubscriptionController@show')->name('show.unsubscription');


But I got Undefined variable => unsubscribe error So I put directly the destroy method instead ...

voilatech's avatar

No need to signing in ... Basically when users subscribe, the notification gets sent to them . and in the same view I put below ;

<a href="{{ route( 'show.unsubscription', $unsubscribe ->id) }}" style="text-decoration:none"; class="brn btn-success btn-lg"> Unsubscribe  </a>

But I got undefined variable : $unsubscribe in my view

Cronix's avatar

But I got undefined variable : $unsubscribe in my view

That's because you called it "info" when you sent it to the view...

change

return view('unsubscribe')->withInfo($unsubscribe);

to

return view('unsubscribe', compact('unsubscribe'));
voilatech's avatar

@Cronix Regardless still throws the same error: Undefined variable: unsubscribe! below is store method in which the notification get sent to users:

public function store(Request $request)
    {
        //validation

        $this->validate($request, [
            'email' => 'required|email',
        ]);

        //save data into DB

        $subscribe = new Subscription();
        $subscribe->email = $request->input('email');
        $result = $subscribe->save();
        if ($result)
        {
            $subscriber = $subscribe->email;
            Mail::to($subscriber)->send(new Subscriber);

            return redirect()->back()->with('alert','You have successfully subscribed!');
        }else{
            return redirect()->back();
        }
    }

the Route:

Route::post('/subscribe', 'Subscription\SubscriptionController@store')->name('subscribe');

Cronix's avatar
Cronix
Best Answer
Level 67

It's most likely coming from here

Mail::to($subscriber)->send(new Subscriber);

You don't pass anything to your new Subscriber. It's basically like sending data to a view...

See the example in the docs where they are doing

Mail::to($request->user())
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->send(new OrderShipped($order));

See, they pass $order to the OrderShipped mailable so $order is available in the mail view.

voilatech's avatar

@Cronix Good point! Now , same error, undefined variable on the destroy method:

The method :

 public function destroy($id)
    {
        $unsubscription = Subscription::find($id);
        $unsubscription->delete();

        Session::flash('unsubscription', 'You have successfully unsubscribed from Our site!' );

        return redirect('/');
    }

The route :

Route::delete('/subscription/{id}', 'Subscription\SubscriptionController@destroy')->name('delete.subscription');

The view:

{!! Form::open(['route' => ['delete.subscription', $unsubscription->id], 'method' => 'DELETE']) !!}

{{Form::submit('Unsubscribe', ['class' => 'btn btn-danger btn-block' ]) }}

{!! Form::close()!!}
Cronix's avatar

This is a bit beyond your original problem which I think is solved on the other page lol. What error? What variable is undefined? Is it about $unsubscription in the view? If so, show what's loading that view.

voilatech's avatar

Well, it throws an error on $unsubscription variable by which I get the id of targeted subscriber and delete it inside of my destroy method. it complains $unsubscription is not declared which is not true! if i removed the route inside of the view above , the page gets loaded no problem and I can see the subscriber's id in the url! as expected Not sure what causing this !

Cronix's avatar

if i removed the route inside of the view above , the page gets loaded no problem and I can see the subscriber's id in the url!

This makes no sense. If you remove the route on the form, how would it possibly be getting the correct id when you submit the form since that's where the id is coming from? Show your whole view file...

Also show your whole controller method that is loading that view. Including public function ....

voilatech's avatar

It's because we passed the data to the email notification when user subscribe as shown above and then The view "unsubscribe" gets loaded from the Show method :

Show method:

  public function show($id)
    {
        $subscribe = Subscription::find($id);

        //return view('unsubscribe')->withUnsubscribe($unsubscribe);
        return view('unsubscribe', compact('subscribe'));
    }

The view:

  <body>
        <div class="flex-center position-ref full-height">
            <div class="content">
                <div class="title m-b-md">
                    <h1>Unsubscription</h1>
                </div>

                <div class="title">
                    <p>We are sorry that you unsubscribe, but we are always there to help you!Test!! </p>


                </div>
                <div class="card">
                    {!! Form::open(['route' => ['delete.subscription', $unsubscription->id], 'method' => 'DELETE']) !!}

                    {{Form::submit('Unsubscribe', ['class' => 'btn btn-danger btn-block' ]) }}

                    {!! Form::close()!!}

                    <a href="{{ route('delete.subscription', $unsubscription->id) }}" style="text-decoration:none"; class="brn btn-success btn-lg"> Unsubscribe  </a>



                </div>

            </div>
        </div>
    </body>
Cronix's avatar

Yeah, you're passing $subscribe in the controller, but you're trying to access $unsubscription in the view... Should be $subscribe->id in the view with the form.

return view('unsubscribe', compact('subscribe'));
//...
{!! Form::open(['route' => ['delete.subscription', $unsubscription->id], 'method' => 'DELETE']) !!}
voilatech's avatar

@ahhh you are right! silly mistake!

Now the subscriber gets deleted ,but it throws an error :

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

It does not redirect to '/' (landing page)!

Cronix's avatar

Jeez, I already solved your original question and solved 2 unrelated issues and we're onto another unrelated issue now. At some point you should be able to solve these basic things yourself... The initial route problem was a little more complex, but all these passing variables to views and accessing them and such are pretty basic things.

MethodNotAllowedHttpException

That always means you're sending the wrong verb to a route. Like if you have a

Route::get('some-endpoint', 'SomeController@show');

and you send a POST request to it. The POST method Is "not allowed" on a GET route.

<a href="{{ route('delete.subscription', $unsubscription->id) }}" style="text-decoration:none"; class="brn btn-success btn-lg"> Unsubscribe  </a>

Is that what you're clicking to unsubscribe? Because html <a> tags always send a GET request. You should use the submit button in the form. I don't know why you have a submit button AND an anchor in the same view.

You should really mark the post as solved though since your original question about the route not showing up in your route:list was solved long ago. If you have other questions it's appropriate to open a new thread.

voilatech's avatar

All good! Thank youl! will mark it done now!

Cronix's avatar

Cool. Just click the checkbox under the persons avatar next to the post that solved your original issue. It helps other people who have the same issue find threads with solutions to the problem.

Please or to participate in this conversation.