【问题标题】:laravel 5.2 page url is changed but view isn't loadedlaravel 5.2 页面 url 已更改但未加载视图
【发布时间】:2016-10-25 20:56:13
【问题描述】:

我想去 create.php 如果用户单击按钮,未登录用户重定向到 index.blade.php 中的登录页面。

但只有页面 URL 被更改。这是我的代码。

index.blade.php

<button class="btn btn-default btn-sm" type="button" aria-expanded="false" onclick="location.href='{{ route('board.create') }}' ">글쓰기</button>

路线

Route::group(['middleware' => 'auth'], function(){
Route::get('board/create', ['as' => 'board.create', 'uses' =>'BoardController@create']);
});

控制器

public function create() {

    return view('board.create');

}

查看create.blade.php

@extends('layouts.app')
@section('content')
.......
@endsection

【问题讨论】:

  • 尝试返回 View::make('board.create');
  • 你应该有这个文件resources/views/board/create.blade.php
  • resources/views/board/create.blade.php 存在。并尝试 return View::make('board.create') is not working T.T

标签: php laravel


【解决方案1】:

我假设如果未登录,您需要将用户重定向到登录页面,否则重定向到创建页面。有了这个,请用if声明检查下面的按钮。你只需要在你的index.blade.php替换我下面的sn-p

@if(Auth::user())
   <button class="btn btn-default btn-sm" type="button" aria-expanded="false" onclick="location.href='{{ route('board.create') }}' ">글쓰기</button>
@else
   <button class="btn btn-default btn-sm" type="button" aria-expanded="false" onclick="location.href='{{ url('/login') }}' ">글쓰기</button>
@endif

让我知道您有任何疑问或我错了。

【讨论】:

  • 我也试过你的,&lt;button class="btn btn-default btn-sm" type="button" aria-expanded="false" onclick="location.href='{{ route('board.create') }}' "&gt;글쓰기&lt;/button&gt; 这部分不起作用。仅更改 URL..
  • 别担心!请检查一下你的mysql错误日志吗?
  • 我查看了开发工具,肯定是 create.blade.php ,但是 create.blade.php 的内容和 index.blade.php 是一样的
  • 我认为视图文件加载成功
  • 是的,这里有什么错误吗?如果您不介意,我需要检查您的代码..
猜你喜欢
  • 2018-05-12
  • 1970-01-01
  • 2017-12-02
  • 1970-01-01
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-27
相关资源
最近更新 更多