【发布时间】:2016-02-27 12:58:13
【问题描述】:
嗨,也许我在这里遗漏了一些东西,但是如果我使用诸如
之类的路线/admin-user-management
然后刀片模板正确渲染。但是使用确切的代码,复制/粘贴到带有路线的另一个视图中
/admin/{id}
然后视图不渲染模板。
两个视图在各个方面都是相同的,一个使用模板正确渲染视图,而另一个带有 slug 的视图不能正确渲染模板,它会随机吐出元素但它不能正确渲染实际布局.
为什么它们会有所不同?这也不是我第一次遇到这种情况,我只是不知道如果 URL 中是否有 slug 会有什么区别。
再一次,两个文件是相同的。
一个是useraccounts函数,另一个是控制器上的show函数。
public function show($id)
{
$user=User::find($id);
return view('admin.show',compact('user'));
}
public function useraccounts()
{
$users = User::all();
return view('admin.useraccounts', compact('users'));
}
显示用户详情的按钮如下
<a href="{{route('admin.show',$user)}}" class="btn btn-primary">View all information</a>
请问有人对我遇到的这个问题有任何想法吗?
admin.show 视图
@extends('admin')
@section('main')
<aside class="right-side">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Dashboard
<small>Control panel</small>
</h1>
<ol class="breadcrumb">
<li><a href="/admin"><i class="fa fa-dashboard"></i> Home</a></li>
<li class="active">Dashboard</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<h3>
{{--53<sup style="font-size: 20px">%</sup>--}}
</h3>
<p>
Statistics
</p>
</div>
<div class="icon">
<i class="ion ion-stats-bars"></i>
</div>
<a href="#" class="small-box-footer">
View Information <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3>
{{--53--}}
</h3>
<p>
User Management
</p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
<a href="/admin-user-management" class="small-box-footer">
Edit Details <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3>
{{--65--}}
</h3>
<p>
Detailed Site Information
</p>
</div>
<div class="icon">
<i class="ion ion-pie-graph"></i>
</div>
<a href="#" class="small-box-footer">
View Data <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
</div><!-- /.row -->
<!-- top row -->
<div class="row">
<div class="col-xs-12 connectedSortable">
</div><!-- /.col -->
</div>
</section><!-- /.content -->
<label>{{$user->name}}</label>
</aside><!-- /.right-side -->
@endsection
然后是正在使用的 admin.admin-user-management 视图
@extends('admin')
@section('main')
<aside class="right-side">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Dashboard
<small>Control panel</small>
</h1>
<ol class="breadcrumb">
<li><a href="/admin"><i class="fa fa-dashboard"></i> Home</a></li>
<li class="active">Dashboard</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<h3>
{{--53<sup style="font-size: 20px">%</sup>--}}
</h3>
<p>
Statistics
</p>
</div>
<div class="icon">
<i class="ion ion-stats-bars"></i>
</div>
<a href="#" class="small-box-footer">
View Information <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3>
{{--53--}}
</h3>
<p>
User Management
</p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
<a href="#" class="small-box-footer">
Edit Details <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3>
{{--65--}}
</h3>
<p>
Detailed Site Information
</p>
</div>
<div class="icon">
<i class="ion ion-pie-graph"></i>
</div>
<a href="#" class="small-box-footer">
View Data <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
</div><!-- /.row -->
<!-- top row -->
<div class="row">
<div class="col-xs-12 connectedSortable">
</div><!-- /.col -->
</div>
</section><!-- /.content -->
<div class="container-fluid">
<div class="form-box">
@if (session('message'))
<div class="alert alert-info" style="text-align: center; width: 200px; ">
{{ session('message') }}
</div>
@endif
<div class="container">
{{-- @if(Auth::user()) --}}
<form class="form-group">
@if($users != null)
@foreach($users as $user)
@if($user->admin != 'true')
{!! Form::label($user->name) !!}
<div class="container">
<br>
<a href="{{route('admin.show', ['id' => $user->id])}}" class="btn btn-primary">View all information</a>
</div>
</br>
<div class="container">
{{-- <a href="{{route('house.edit',$house)}}" class="btn btn-primary">Update house details</a> --}}
</div>
<br>
<div class="container">
{{-- {!! Form::open(['method' => 'DELETE', 'route'=>['house.destroy', $house->id]]) !!} --}}
{{-- {!! Form::submit('Delete House', ['class' => 'btn btn-danger']) !!} --}}
{{-- {!! Form::close() !!} --}}
</div>
@endif
@endforeach
@else
{{-- <li><a href={{url('/house/create')}}>Add new house</a></li> --}}
@endif
</form>
{{-- @endif --}}
</div>
</div>
</div>
</aside><!-- /.right-side -->
@endsection
routes.php 文件
//Admin Routes
Route::get('/admin-user-management', 'AdminController@useraccounts');
Route::resource('admin', 'AdminController');
标题
<head>
<meta charset="UTF-8">
<title>Admin | Dashboard</title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- bootstrap 3.0.2 -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- font Awesome -->
<link href="bootstrap/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link href="bootstrap/css/ionicons.min.css" rel="stylesheet" type="text/css" />
<!-- Morris chart -->
<link href="bootstrap/css/morris/morris.css" rel="stylesheet" type="text/css" />
<!-- jvectormap -->
<link href="bootstrap/css/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" />
<!-- fullCalendar -->
<link href="bootstrap/css/fullcalendar/fullcalendar.css" rel="stylesheet" type="text/css" />
<!-- Daterange picker -->
<link href="bootstrap/css/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<!-- bootstrap wysihtml5 - text editor -->
<link href="bootstrap/css/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="bootstrap/css/AdminLTE.css" rel="stylesheet" type="text/css" />
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
【问题讨论】:
-
您能分享包含 css 样式表的标题部分吗
-
我添加了标题的信息,但是正如我所提到的,即使代码重复,也只有一个正确呈现而另一个没有,所以我认为标题信息在某种程度上是无关紧要的,但如果它确实有帮助,然后我添加了它:)
-
我猜,css文件放在public/admin/bootstrap?
-
是的,这是正确的 :) 这似乎是路径中的问题。
-
很高兴为您提供帮助,如果您愿意,我可以添加答案,以造福社区。span>
标签: templates laravel routes blade slug