首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在航海家中创建视图:未连接到模型

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

Stack Overflow用户
提问于 2021-09-23 16:34:22
回答 1查看 831关注 0票数 0

我需要创建一个视图在laravel管理旅行者发送通知使用防火墙。因此,问题在于如何创建该视图,以及如何在管理菜单中创建自定义链接。我试着用laravel-admin使用表单,这是我在laravel-admin中使用的代码。

代码语言:javascript
复制
<?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'      => '',
            
        ];
    }
}

后来我试着在航海者身上做同样的事,但是失败了.

我希望我的解释能帮上忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-23 21:51:16

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

  1. 在管理路由组中的web.php中添加您的路由,如:

代码语言:javascript
复制
Route::group(['prefix' => 'admin'], function () {
    Route::get('notifications', function(){
        return view('notifications');
    });
    Voyager::routes();
});

  1. 创建了一个新的视图,例如,这里我称为notifications,它扩展了航海家的主布局,如:

代码语言:javascript
复制
@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访问此页面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69303823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档