如何在航海者中创建视图::未连接到模型

how to create view in voyager :::not connected to model

我需要在 laravel admin voyager 中创建一个视图以使用 firebase 发送通知。 所以问题是如何创建该视图以及如何在管理菜单中创建自定义 link。 我尝试使用 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'      => '',
            
        ];
    }
}

然后我尝试在航海者中做同样的事情但是失败了...

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

根据您的问题,我了解到您正试图在 Voyager 中添加一个属于 admin 但未连接到 Model 的新视图,您可以通过以下步骤完成此操作:

  1. 将您的路线添加到管理路线组内的 web.php 中,例如:
Route::group(['prefix' => 'admin'], function () {
    Route::get('notifications', function(){
        return view('notifications');
    });
    Voyager::routes();
});
  1. 创建一个新视图,例如我在这里调用 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
  1. 最后,在内容部分添加您想要的内容,您可以通过导航访问此页面:{url}/admin/notifications