如何在voyager:::中创建未连接到模型的视图



我需要在laravel admin voyager中创建一个视图来使用firebase发送通知。所以问题是如何创建该视图以及如何在管理菜单中创建自定义链接。我试着用laravell -admin使用表单这是我在laravell -admin

中使用的代码
<?php
namespace AppAdminForms;
use EncoreAdminWidgetsForm;
use IlluminateHttpRequest;
class sendnot extends Form
{
/**
* The form title.
*
* @var string
*/
public $title = '';
/**
* Handle the form request.
*
* @param Request $request
*
* @return IlluminateHttpRedirectResponse
*/
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'      => '',

];
}
}

然后我试着在航海家做同样的事情,但失败了…

我希望我的解释对你有帮助

我从你的问题中理解到,你正试图在Voyager中添加一个属于admin但未连接到Model的新视图,你可以通过以下步骤做到这一点:

  1. 在admin路由组内的web.php中添加您的路由,如:
Route::group(['prefix' => 'admin'], function () {
Route::get('notifications', function(){
return view('notifications');
});
Voyager::routes();
});
  1. 创建一个新视图,例如这里我将其命名为notifications,它扩展了voyager master布局,如下:
@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
  1. 最后,在内容部分添加您想要的内容,您可以通过导航访问此页面:{url}/admin/notifications

最新更新