我需要创建一个视图在laravel管理旅行者发送通知使用防火墙。因此,问题在于如何创建该视图,以及如何在管理菜单中创建自定义链接。我试着用laravel-admin使用表单,这是我在laravel-admin中使用的代码。
<?php
namespace App\Admin\Forms;
use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;
class sendnot extends Form
{
/**
* The form title.
*
* @var string
*/
public $title = '';
/**
* Handle the form request.
*
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse
*/
public function handle(Request $req)
{
//dump($request->all());
$url = 'https://fcm.googleapis.com/fcm/send';
$dataArr = array('click_action' => 'FLUTTER_NOTIFICATION_CLICK', 'id' => $req->id,'status'=>"done");
$notification = array('title' =>$req->title, 'text' => $req->message, 'sound' => 'default', 'badge' => '1',);
$arrayToSend = array('to' => "/topics/all", 'notification' => $notification, 'data' => $dataArr, 'priority'=>'high');
$fields = json_encode ($arrayToSend);
$headers = array (
'Authorization: key=' . "XXXXXX",
'Content-Type: application/json'
);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
//var_dump($result);
curl_close ( $ch );
admin_success('Processed successfully.'. $result);
return back();
}
/**
* Build a form here.
*/
public function form()
{
$this->text('title')->rules('required');
$this->textarea('message')->rules('required');
}
/**
* The data of the form.
*
* @return array $data
*/
public function data()
{
return [
'title' => '',
'message' => '',
];
}
}后来我试着在航海者身上做同样的事,但是失败了.
我希望我的解释能帮上忙
发布于 2021-09-23 21:51:16
正如我从您的问题中了解到的,您正试图在Voyager中添加一个属于admin但未连接到Model的新视图,您可以通过以下步骤实现这一点:
web.php中添加您的路由,如:Route::group(['prefix' => 'admin'], function () {
Route::get('notifications', function(){
return view('notifications');
});
Voyager::routes();
});notifications,它扩展了航海家的主布局,如:@extends('voyager::master')
@section('css')
<style></style>
@stop
@section('page_title', 'Your title')
@section('page_header')
<h1 class="page-title">
<i class="fa fa-home"></i>
Test
</h1>
@include('voyager::multilingual.language-selector')
@stop
@section('content')
<div class="page-content container-fluid">
<h1>Your content</h1>
</div>
@stop最后,在内容部分添加您想要的内容,您可以通过导航:{url}/admin/notifications访问此页面。
https://stackoverflow.com/questions/69303823
复制相似问题