Level 50
@birdietorerik According to the error you have not imported the Notification in controller
use Illuminate\Support\Facades\Notification;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi!
I want to use notification in laravel
But when i tryed notification i get this error message
ERROR - Class 'App\Http\Controllers\Api\V1\Admin\Notification' not found
My Notfification file:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class flowNotification extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($name)
{
$this->name = $name;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'name' =>$this->name
];
}
}
My controller that i use the notification
<?php
namespace App\Http\Controllers\Api\V1\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreUserRequest;
use App\Http\Requests\UpdateUserRequest;
use App\Http\Resources\Admin\UserResource;
use App\Models\Country;
use App\Models\Golfclub;
use App\Models\Role;
use App\Models\User;
use App\Models\Manwomen;
use App\Notifications\flowNotification;
use Illuminate\Support\Facades\Gate;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class UsersApiController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
* Check if user is logged in
*/
public function __construct()
{
$this->middleware(['auth', 'verified']);
}
public function index()
{
abort_if(Gate::denies('user_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');
// Show only users for golfclub related to user
$usersAPI = new UserResource(
User::with(['roles', 'country', 'golfclub', 'manwomen'])
->where('golfclub_id', auth()->user()->golfclub_id)
->advancedFilter()
);
return $usersAPI;
}
public function store(StoreUserRequest $request)
{
$user = User::create($request->validated());
$user->roles()->sync($request->input('roles.*.id', []));
$testuser = auth()->user();
Notification::send($testuser, new flowNotification("TEST DATA NOTIFICATION"));
return (new UserResource($user))
->response()
->setStatusCode(Response::HTTP_CREATED);
}
public function create(User $user)
{
abort_if(Gate::denies('user_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$golfID = auth()->user()->golfclub_id;
return response([
'meta' => [
'roles' => Role::where('id', '<>', 4)->get(['id', 'title']),
'country' => Country::get(['id', 'name']),
'golfclub' => Golfclub::get(['id', 'name']),
'manwomen' => Manwomen::get(['id', 'name']),
],
]);
}
public function show(User $user)
{
abort_if(Gate::denies('user_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');
return new UserResource($user->load(['roles', 'country', 'golfclub', 'manwomen']));
}
public function update(UpdateUserRequest $request, User $user)
{
$user->update($request->validated());
$user->roles()->sync($request->input('roles.*.id', []));
return (new UserResource($user))
->response()
->setStatusCode(Response::HTTP_ACCEPTED);
}
public function edit(User $user)
{
abort_if(Gate::denies('user_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');
return response([
'data' => new UserResource($user->load(['roles', 'country', 'golfclub', 'manwomen'])),
'meta' => [
'roles' => Role::get(['id', 'title']),
'country' => Country::get(['id', 'name']),
'golfclub' => Golfclub::get(['id', 'name']),
'manwomen' => Manwomen::get(['id', 'name']),
],
]);
}
public function destroy(User $user)
{
abort_if(Gate::denies('user_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$user->delete();
return response(null, Response::HTTP_NO_CONTENT);
}
public function userprofile()
{
$userID = auth()->user()->id;
$profil = User::getprofile($userID);
return $profil;
}
public function storeGpstracking(Request $request)
{
$status = $request->status;
$updatedstatus = User::storeGpstracking($status);
return $updatedstatus;
}
public function getdefaulUser(Request $request){
$usersdata = User::getDefaultUser();
return $usersdata;
}
}
Cant figer out what the problem is ?
@birdietorerik According to the error you have not imported the Notification in controller
use Illuminate\Support\Facades\Notification;
Please or to participate in this conversation.