我是 laravel 的新手,我正在尝试在数据库中的类别表和设备表之间建立对多关系
在类别 View 中,我拥有所有类别,我希望当我点击一个类别时转到另一个 View 并显示该类别的所有设备
它适用于我对类别和显示方法使用 rsource Controller :CatgoryController.php
public function show($id)
{
$categories = Category::find($id);
$all_devices = $categories->devices;
return view('devices',compact('categories',$categories,'all_devices',$all_devices));
}
在设备 View 中我做的是:
devices.blade.php
@extends('master')
@section('content')
<div class="container">
<div class="row">
<div class="col-lg-12 text-center animateup">
<div class="inline-icons-text section-heading">
<div class="inline-icon">
<hr/><hr/><hr/><hr/><hr/>
</div>
<span class="inline-icon heading-width">
<span class="heading-text"><h1> {{$categories->category_name}} </h1> </span>
</span>
<div class="inline-icon">
<hr/><hr/><hr/><hr/><hr/>
</div>
</div>
</div>
</div>
<br/>
<div class="row text-center">
@foreach ($all_devices as $device)
<div class="col-md-3 col-sm-6 animateleft">
<h5>
<a href="#">{{$device->device_name}}</a>
<span class="glyphicon glyphicon-chevron-right"></span>
</h5>
</div>
@endforeach
</div>
</div>
@stop
这就是我显示所有类别的方式,当单击一个类别时,它会转到其他 View 以显示该类别的设备
categories.blade.php
<div class="row text-center">
@foreach ($categories as $categories)
<div class="col-md-3 col-sm-6 animateleft">
<h5>
<a href="categories/{{$categories->id}}">{{$categories->category_name}}</a>
<span class="glyphicon glyphicon-chevron-right"></span>
</h5>
</div>
@endforeach
</div>
最后这是我的溃败 Rout.php
Route::resource('categories','CategoryController');
Route::resource('/devices','DevicesController');
我的问题是一切正常,但具有某一类别设备的页面没有网站的样式
最佳答案
将你的 stylesto 公共(public)文件夹移动到任何子文件夹中..这里我使用设备作为子文件夹,devices.css 是我的文件.. 将这样的链接放在你的主 Blade 中。使用你的文件夹和文件名
<link rel="stylesheet" href="{{URL::to('/')}}/devices/devices.css">
关于php - laravel show 方法没有样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46326251/