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

esaeng's avatar

Symfony\Component\Routing\Exception\RouteNotFoundException Route [login] not defined.

I am working on notifications in Laravel. Here I am getting an error. Route Not Found..Suggestions Plzzz...!! Here is my Routes File....

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| 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 "web" middleware group. Now create something great!
|
*/

// Route::get('/', function () {
//     return view('welcome');
// });


Route::get('/', 'App\Http\Controllers\EmployeeController@getData');


Route::get('/home', function () {
    return App\Models\Employee::paginate(5);
});



Route::get('students', [
    'uses' => 'App\Http\Controllers\StudentController@index',
    'as' => 'student-list'
]);


Route::get('sort','App\Http\Controllers\StudentController@sort1');
Route::get('sort','App\Http\Controllers\StudentController@sort2');


Route::get('sort','App\Http\Controllers\StudentController@sort');


Route::get('indexSort','App\Http\Controllers\StudentController@indexSort');
Route::get('indexBetween','App\Http\Controllers\StudentController@indexBetween');
Route::get('indexCarbon','App\Http\Controllers\StudentController@indexCarbon');
Route::get('indexGroupBy','App\Http\Controllers\StudentController@indexGroupBy');



//Import/Export Excel Sheet

Route::get('file-import-export', 'App\Http\Controllers\SheetController@fileImportExport');
Route::post('file-import', 'App\Http\Controllers\SheetController@fileImport')->name('file-import');
Route::get('file-export', 'App\Http\Controllers\SheetController@fileExport')->name('file-export');


//Notification
Route::get('send-notification', 'App\Http\Controllers\NotificationController@sendOfferNotification');

And here is my Notification controller.

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

use App\Models\Employee;
use Notification;
use App\Notifications\OffersNotification;

class NotificationController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
  
    public function index()
    {
        return view('welcome');
    }
    
    public function sendOfferNotification() {
        $userSchema = Employee::first();
        dd($userSchema);
  
        $offerData = [
            'name' => 'BOGO',
            'body' => 'You received an offer.',
            'thanks' => 'Thank you',
            'offerText' => 'Check out the offer',
            'offerUrl' => url('/'),
            'offer_id' => 007
        ];
  
        Notification::send($userSchema, new OffersNotification($offerData));
   
        dd('Task completed!');
    }
}
0 likes
2 replies
AdamT's avatar

Could this be because you are using the auth middleware in the constructor?

1 like
esaeng's avatar

@adamt Yes I removed it from controller... Now another problem is coming... Call to undefined method Illuminate\Notifications\Messages\MailMessage::name() error is on line 45 code of OffersNotification.php

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class OffersNotification extends Notification
{
    use Queueable;
    private $offerData;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($offerData)
    {
        $this->offerData = $offerData;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail','database'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)                    
            ->name($this->offerData['name'])
            ->line($this->offerData['body'])
            ->action($this->offerData['offerText'], $this->offerData['offerUrl'])
            ->line($this->offerData['thanks']);
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'offer_id' => $this->offerData['offer_id']
        ];
    }
}

Please or to participate in this conversation.