我有一个layouts/app.blade.php视图,我产生一个内容部分.
布局/ app.blade.php
@yield('content')
Run Code Online (Sandbox Code Playgroud)
adminpanel/adminpanel.blade.php
@extends('layouts.app')
@section('content')
<div id="wrapper">
<div id="sidebar-wrapper">
@yield('sidebar')
</div>
<div id="page-content-wrapper">
<div class="container-fluid">
@yield('page-content')
</div>
</div>
</div>
@endsection
Run Code Online (Sandbox Code Playgroud)
adminpanel/sidebar.blade.php
@extends('adminpanel.adminpanel')
@section('sidebar')
<ul class="sidebar-nav">
<li class="sidebar-brand">
<a href="#">
Profile
</a>
</li>
<li>
<a href="#">Dashboard</a>
</li>
<li>
<a href="#">News</a>
</li>
</ul>
@endsection
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗?
当我在adminpanel/adminpanel.blade.php视图中键入内容时,它可以正常工作,但是部分的屈服不起作用.
我的目标是能够在刀片视图中执行类似的操作。
<Example name="{{ $user->name }}" />
Run Code Online (Sandbox Code Playgroud)
但这并没有渲染任何东西。
当我这样做时:<div id="example"></div>它呈现的组件没有正常的props值。
因此,我试图将来自控制器的数据作为道具传递给我的React组件。
我不确定是否有可能。
这是我的App.js:
require('./components/Example');
Run Code Online (Sandbox Code Playgroud)
这是我的Example.js组件:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class Example extends Component {
render() {
return (
<div className="container">
<div className="row">
<div className="col-md-8 col-md-offset-2">
<div className="panel panel-default">
<div className="panel-heading">Example</div>
<div className="panel-body">
Hello, {this.props.name}
</div>
</div>
</div>
</div>
</div>
);
}
}
if (document.getElementById('example')) {
ReactDOM.render(<Example />, document.getElementById('example'));
}
Run Code Online (Sandbox Code Playgroud) 我calculate-cars根据我在发出请求的表单中输入的数据查询路线并显示其他视图,其中包含我查询的数据,但是当有人直接访问此路线时,我想重定向到主页.
不幸的是我一直收到这个错误:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException没有消息
我的路线:
Route::post('calculate-cars', 'CarsController@calculateCars');
我知道我得到这个错误,因为我直接访问后路由但我在我的控制器方法中尝试这个但我仍然得到相同的错误:
if (!$request->isMethod('post')) {
return redirect()->to('/');
}
Run Code Online (Sandbox Code Playgroud) 我有一个自定义表单请求,我在其中执行一些额外的验证逻辑,如果我的逻辑失败,我想添加一个错误,但我收到此错误:
对 null 调用成员函数errors()
这是我的自定义请求:
if (!empty($this->get('new_password')) && !empty($this->get('current_password'))) {
if (
!Auth::attempt([
'email' => $this->get('email'),
'password' => $this->get('current_password'),
'status' => 'pending'
])
) {
$this->validator->errors()->add('current_password', 'Something is wrong with this field!');
}
}
return [
'first_name' => 'required|min:1|max:190',
];
Run Code Online (Sandbox Code Playgroud)
class ProfileRequest extends FormRequest
{
public function authorize()
{
return Auth::check();
}
public function rules()
{
if (!empty($this->get('new_password')) && !empty($this->get('current_password'))) {
if (
!Auth::attempt([
'email' => $this->get('email'),
'password' => $this->get('current_password'),
'status' => 'pending'
])
) {
$this->validator->getMessageBag()->add('current_password', 'Something is …Run Code Online (Sandbox Code Playgroud)