Laravel 5.3 - 刀片无效

时间:2017-01-09 06:53:00

标签: laravel blade

当我尝试在Web浏览器上加载项目时。它显示页眉和页脚,但缺少包含表单的中间部分,我不明白我做错了什么?

视图/ welcome.blade:

<!DOCTYPE html>
<html lang="en">
<head>
@include('partials._head')
</head>
<body>
         @include('partials._nav')


         <div class="container">

         @include('partials._messages')
         @yield('content')
         @include('partials._footer')

         </div>


         @include('partials._javascript')

 </body>
 </html>

视图/ USER_AUTH / user_register.blade:

@extends('welcome')

@section('title')
Welcome!!
@endsection

@section('content')

{!! Form::open(['route' => 'signup']) !!}

{{ Form::label('user_name','Name:') }}
{{ Form::text('user_name',null,['class' => 'form-control']) }}

{{ Form::label('email','E-mail:') }}
{{ Form::text('email',null,['class' => 'form-control']) }}

{{ Form::label('mobile_num','Mobile No.:') }}
{{ Form::text('mobile_num',null,['class' => 'form-control']) }}

{{ Form::label('address','Address:') }}
{{ Form::text('address',null,['class' => 'form-control']) }}

{{ Form::label('state','State:') }}
{{ Form::text('state',null,['class' => 'form-control']) }}

{{ Form::label('city','City:') }}
{{ Form::text('city',null,['class' => 'form-control']) }}

{{ Form::label('district','District:') }}
{{ Form::text('district',null,['class' => 'form-control']) }}


{{ Form::submit('Register',array('class' => 'btn btn-success btn-lg btn-  block form-spacing-top')) }}

{!! Form::close() !!}
@endsection

RegisterController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class RegisterController extends Controller
{

public function getRegistrationPage()
   {  

         return view('user_auth.user_register');
   }
public function postSignUp(Request $request)
 {
    $this -> validate($request,[  
      'email' => 'required|email|unique:users',
      'name'  => 'required|max:20',
      'mobile_num' => 'required|digits:10',
      'address' => 'required',
      'city' => 'required',
      'district' => 'required',
      'state' => 'required',
      'password' => 'required|min:4'
      ]);

    $email = $request['email'];
    $name = $request['name'];
    $mobile_num = $request['mobile_num'];
    $address = $request['address'];
    $city = $request['city'];
    $district = $request['district'];
    $state = $request['state'];
    $password = bcrypt($request['password']);

    $user = new User();
    $user->email =$email;
    $user->name = $name;
    $user->mobile_num = $mobile_num;
    $user->address = $address;
    $user->city = $city;
    $user->district = $district;
    $user->state = $state;
    $user->password = $password;

    $user->save();

    return redirect()->route('dashboard');

    Auth::login($user);
 }

 public function postSignIn(Request $request)
 { 
    $this -> validate($request,[
        'mobile_num' => 'required',
        'password' => 'required'
        ]);

   if(Auth::attempt(['mobile_num' => $request['mobile_num'], 'password' =>  $request['password']]))  {

        return redirect()->route('dashboard');
    }

        return redirect()->back();          
  }

  public function getDashboard()
   {  

         return view('pages.dashboard');
   }


  }

routes / web.php:

Route::group(['middleware' => ['web']], function(){

Route::get('/', function () {
    return view('welcome');
})->name('home');

Route::post('/signup',[
    'uses' => 'RegisterController@postSignUp',
    'as'   => 'signup'
    ]);

Route::post('/signin',[
    'uses' => 'RegisterController@postSignIn',
    'as'   => 'signin'
    ]);

Route::get('/dashboard',[
     'uses' => 'RegisterController@getDashboard',
     'as'   => 'dashboard',
     'middleware' => 'auth'
    ]);
Route::get('/register',[
     'uses' => 'RegisterController@getRegistrationPage',
     'as'   => 'register',
     'middleware' => 'auth'
    ]);

});

2 个答案:

答案 0 :(得分:2)

您需要返回user_register视图extend layout(在这种情况下称为welcome):

@extends('welcome')

或者您可以致电welcomeinclude user_register查看:

@include('user_auth.user_register')

这取决于您希望实现的目标,但将welcome重命名为layout并将其扩展为正确的解决方案。

同时将文件重命名为.blade.php,因为现在名称类似于welcome.blade而不是welcome.blade.php

答案 1 :(得分:0)

您的代码是正确的但是请检查您的路由文件您是否调用了user_register路由? 您已将欢迎页面设置为布局文件,因此当您打开欢迎页面时,它仅显示标题和列表。您已包含的页脚文件。