I have a button that sends a notification. This is the request button. Only what I write to the toArray method is sent to the database in the data field. Now this is my 'message'. How can I change the data field outside the Notify.php file? That is, when the request button is pressed, a form should be opened, into which data is entered, which are then sent to the database instead of 'message'.First, tell me at least how I can fill in the data field, and I'll figure it out with the form myself. I am new to php laravel. I hope you can help me. web.php:
<?php
use App\User;
use App\Notifications\Notify;
use Illuminate\Support\Facades\Notification;
Route::name('user.')->group(function (){
Route::get('/private',function (){
return view('private');
});
Route::view('/private','private')->middleware('auth')->name('private');
Route::get('/login',function(){
if(Auth::check()){return redirect(route('user.private'));}
// ?????????�?????� ???� ?�???�???????�?�?�???? ?????�???�?????�?�?�?�??. ?�???�?? ???�?� ?�???�???????�?????�??, ?�?? ???�???????�???� ???� ???�???�?????�?? ???????�???�??
return view('login');
})->name('login');
Route::post('/login',[\App\Http\Controllers\LoginController::class,'login']);
Route::get('/logout',function(){
Auth::logout();
return redirect('/');
})->name('logout');
Route::get('/registration', function () {
if(Auth::check()){
return redirect(route('user.private'));
}
return view('registration');
})->name('registration');
Route::post('/registration',[\App\Http\Controllers\RegisterController::class,'save']);
Route::get('/private/request',function (){
$users = User::all();
Notification::send($users,new App\Notifications\Notify);
return redirect(route('user.private'));
});
Route::get('/private/markAsRead',function (){
auth()->user()->unreadNotifications->markAsRead();
return redirect()->back();
});
});
private.blade.php:
@extends('layouts.app')
@section('title-block')
???????�???�??
@endsection
@section('content')
<p>?????�?????? ???�?? ?�???�?�???�???�???�?????????�???�?� ?????�???�?????�?�?�?�?�??</p>
<a href="/logout"><button onlick="return false;">LogOut</button></a> <p>
<?php $id = Auth::id();
$user = DB::table('users')->find($id);
?>
{{$user->surname}}
{{$user->name}}
{{$user->fathers_name}}
{{$user->number}}
{{$user->studies}}
<p> <a href="/private/request"><button onlick="return false;">Request</button></a> <p>
<a href="#"></a>
<li class ='dropdown'>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true">
<i class="fa fa-bell"></i>
<span class="badge bg-secondary">{{auth()->user()->unreadNotifications->count()}}</span>
</a>
<li ><a href="/private/markAsRead" style="color: green">Mark all as Read</a></li>
<ul >
@foreach(auth()->user()->readNotifications as $notification)
<li><a href="#"> {{$notification->data['data']}}</a>
</li>
@endforeach
@foreach(auth()->user()->unreadNotifications as $notification)
<li style="background-color: lightgray"><a href="#"> {{$notification->data['data']}}</a>
</li>
@endforeach
</ul>
</li>
@endsection
Notifications/Notify.php:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class Notify extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* 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 [
'data' => 'message'
];
}
}
This is screen from my database: Here, instead of message, there should be my data enter image description here
you need to use attributes in notifiable object not just typing the attributes (message) like this:
$notifiable->message
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.