我有一个简单的CRUD应用程序,我想在其中以Bootstrap弹出模式显示标签。
这是到目前为止我尝试过的。
标签控制器
class TagController extends Controller
{
public function index()
{
$tags =Tag::all();
return view('pages.index')->withTags($tags);
}
public function store(Request $request)
{
$this->validate($reguest, array('name'=>'required|max:255'));
$tag = new Tag;
$tag->name = $request->name;
$tag->save();
$request->session()->flash('succes', 'Tag was successful created!');
return redirect()->route('pages.index');
}
}
现在我想将这些标签显示到与另一个控制器
PageListController
关联的视图中>
这里是视图pages.index
@extends('layouts.app', ['activePage' => 'table', 'titlePage' => __('Table List')]) @section('content') <div class="card-body"> <div class="table-responsive"> <table class="table"> <thead class=" text-primary"> <th> ID </th> <th> Page Name </th> <th> Articles </th> <th> Tags </th> </thead> <tbody> @foreach ($pages as $page) <tr> <td> {{$page->id}} </td> <td> {{$page->pagetitle}} </td> <td> {{$page->articlelist}} </td> <td> <button type="button" class="btn btn-sm btn-success" data-toggle="modal" data-target="#tagsModel"> {{ __('view tags') }} </button> <!-- Modal --> <div class="modal fade" id="#tagsModel" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <table class="table"> <thead class=" text-primary"> <th> ID </th> <th> name </th> </thead> <tbody> @foreach ($tags as $tag) <tr> <td> {{$tag->id}} </td> <td> {{$tag->name}} </td> </tr> @endforeach </tbody> </table> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div> </div> </td> </tr> @endforeach </tbody> </table> </div> </div> @endsection
这是我的路线文件
web.php
<?php Route::get('/', function () { return view('welcome'); }); Auth::routes(); Route::get('/home', 'HomeController@index')->name('home')->middleware('auth'); Route::resource('pages', 'PageListController'); Route::resource('pages', 'TagController'); Route::group(['middleware' => 'auth'], function () { Route::get('table-list', function () { return view('pages.index'); })->name('table'); }); Route::group(['middleware' => 'auth'], function () { Route::resource('user', 'UserController', ['except' => ['show']]); Route::get('profile', ['as' => 'profile.edit', 'uses' => 'ProfileController@edit']); Route::put('profile', ['as' => 'profile.update', 'uses' => 'ProfileController@update']); Route::put('profile/password', ['as' => 'profile.password', 'uses' => 'ProfileController@password']); });
我只想使用引导程序模式弹出窗口显示标签。
现在,当我运行我的应用程序时,出现以下错误
Undefined variable: pages (View: C:\custom-xammp\htdocs\royalad-dashboard\resources\views\pages\index.blade.php)
我的代码在做什么错?任何帮助或建议将不胜感激
我有一个简单的CRUD应用程序,我想在其中以引导弹出窗口的方式显示标签。到目前为止,这是我尝试过的。标签控制器类TagController扩展了Controller {public function ...
您正在使用刀片服务器中的$ pages,该页面尚未发送。仅发送了$ tags。
更改代码...您正在$tags
中分配数据。但是您没有分配$pages
并将其传递给视图。
像这样更改index()
函数上的代码: