Laravel 5 系列入门教程(四)【最适合中国人的 Laravel 教程】【完结】

本教程示例代码见:https://github.com/johnlui/Learn-Laravel-5  

大家在任何地方卡住,最快捷的解决方式就是去看我的示例代码。

本文是本系列教程的完结篇,我们将一起给 Page 加入评论功能,让游客在前台页面可以查看、提交、回复评论,同时我们将在后台完善评论管理功能,可以删除、编辑评论。Page 和评论将使用 Eloquent 提供的“一对多关系”。最终,我们将得到一个个人博客系统的雏形,并布置一个大作业,供大家实战练习。

1. 初识 Eloquent

Laravel Eloquent ORM 是 Laravel 中非常重要的部分,也是 Laravel 能如此流行的原因之一。中文文档在:

1. http://laravel-china.org/docs/5.0/eloquent

2. http://www.golaravel.com/laravel/docs/5.0/eloquent/

在前面的教程中已经建立好的 learnlaravel5/app/Page.php 就是一个 Eloquent Model 类:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Page extends Model {

	//

}

若想进一步了解 Eloquent,推荐阅读系列文章:深入理解 Laravel Eloquent

2. 创建 Comment 模型

首先我们要新建一张表来存储 Comment,命令行运行:

php artisan make:model Comment

成功以后,修改 migration 文件 learnlaravel5/database/migrations/***_create_comments_table.php 的相应位置为:

Schema::create('comments', function(Blueprint $table)
{
	$table->increments('id');
	$table->string('nickname');
	$table->string('email')->nullable();
	$table->string('website')->nullable();
	$table->text('content')->nullable();
	$table->integer('page_id');
	$table->timestamps();
});

之后运行:

php artisan migrate

去数据库里瞧瞧,comments 表已经躺在那儿啦。

3. 建立“一对多关系”

修改 Page 模型:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Page extends Model {

  public function hasManyComments()
  {
    return $this->hasMany('App\Comment', 'page_id', 'id');
  }

}

搞定啦~ Eloquent 中模型间关系就是这么简单。

模型间关系中文文档:http://laravel-china.org/docs/5.0/eloquent#relationships

扩展阅读:深入理解 Laravel Eloquent(三)——模型间关系(关联)

4. 前台提交功能

修改 Comment 模型:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model {

  protected $fillable = ['nickname', 'email', 'website', 'content', 'page_id'];

}

增加一行路由:

Route::post('comment/store', 'CommentsController@store');

运行以下命令创建 CommentsController 控制器:

php artisan make:controller CommentsController

修改 CommentsController:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use Redirect, Input;

use App\Comment;

class CommentsController extends Controller {

	public function store()
	{
		if (Comment::create(Input::all())) {
			return Redirect::back();
		} else {
			return Redirect::back()->withInput()->withErrors('评论发表失败!');
		}

	}

}

修改视图 learnlaravel5/resources/views/pages/show.blade.php:

@extends('_layouts.default')

@section('content')
  <h4>
    <a href="/">⬅️返回首页</a>
  </h4>

  <h1 style="text-align: center; margin-top: 50px;">{{ $page->title }}</h1>
  <hr>
  <div id="date" style="text-align: right;">
    {{ $page->updated_at }}
  </div>
  <div id="content" style="padding: 50px;">
    <p>
      {{ $page->body }}
    </p>
  </div>
  <div id="comments" style="margin-bottom: 100px;">

    @if (count($errors) > 0)
      <div class="alert alert-danger">
        <strong>Whoops!</strong> There were some problems with your input.<br><br>
        <ul>
          @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
          @endforeach
        </ul>
      </div>
    @endif

    <div id="new">
      <form action="{{ URL('comment/store') }}" method="POST">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <input type="hidden" name="page_id" value="{{ $page->id }}">
        <div class="form-group">
          <label>Nickname</label>
          <input type="text" name="nickname" class="form-control" style="width: 300px;" required="required">
        </div>
        <div class="form-group">
          <label>Email address</label>
          <input type="email" name="email" class="form-control" style="width: 300px;">
        </div>
        <div class="form-group">
          <label>Home page</label>
          <input type="text" name="website" class="form-control" style="width: 300px;">
        </div>
        <div class="form-group">
          <label>Content</label>
          <textarea name="content" id="newFormContent" class="form-control" rows="10" required="required"></textarea>
        </div>
        <button type="submit" class="btn btn-lg btn-success col-lg-12">Submit</button>
      </form>
    </div>

<script>
function reply(a) {
  var nickname = a.parentNode.parentNode.firstChild.nextSibling.getAttribute('data');
  var textArea = document.getElementById('newFormContent');
  textArea.innerHTML = '@'+nickname+' ';
}
</script>

    <div class="conmments" style="margin-top: 100px;">
      @foreach ($page->hasManyComments as $comment)

        <div class="one" style="border-top: solid 20px #efefef; padding: 5px 20px;">
          <div class="nickname" data="{{ $comment->nickname }}">
          @if ($comment->website)
            <a href="{{ $comment->website }}">
              <h3>{{ $comment->nickname }}</h3>
            </a>
          @else
            <h3>{{ $comment->nickname }}</h3>
          @endif
            <h6>{{ $comment->created_at }}</h6>
          </div>
          <div class="content">
            <p style="padding: 20px;">
              {{ $comment->content }}
            </p>
          </div>
          <div class="reply" style="text-align: right; padding: 5px;">
            <a href="#new" onclick="reply(this);">回复</a>
          </div>
        </div>

      @endforeach
    </div>
  </div>
@endsection

前台评论功能完成。

查看效果:

Image


Image

5. 后台管理功能

修改基础视图 learnlaravel5/resources/views/app.blade.php 为:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Laravel</title>

	<link href="/css/app.css" rel="stylesheet">

	<!-- Fonts -->
  <link href='http://fonts.useso.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>
</head>
<body>
	<nav class="navbar navbar-default">
		<div class="container-fluid">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
					<span class="sr-only">Toggle Navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="#">Learn Laravel 5</a>
			</div>

			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav">
					<li><a href="/admin">后台首页</a></li>
				</ul>
				<ul class="nav navbar-nav">
					<li><a href="/admin/comments">管理评论</a></li>
				</ul>

				<ul class="nav navbar-nav navbar-right">
					@if (Auth::guest())
						<li><a href="/auth/login">Login</a></li>
						<li><a href="/auth/register">Register</a></li>
					@else
						<li class="dropdown">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ Auth::user()->name }} <span class="caret"></span></a>
							<ul class="dropdown-menu" role="menu">
								<li><a href="/auth/logout">Logout</a></li>
							</ul>
						</li>
					@endif
				</ul>
			</div>
		</div>
	</nav>

	@yield('content')

	<!-- Scripts -->
	<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
</body>
</html>

修改后台路由组(增加了一行):

Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'middleware' => 'auth'], function()
{
  Route::get('/', 'AdminHomeController@index');
  Route::resource('pages', 'PagesController');
  Route::resource('comments', 'CommentsController');
});

创建 Admin\CommentsController :

php artisan make:controller Admin/CommentsController

Admin/CommentsController 要有 查看所有、查看单个、POST更改、删除四个接口:

<?php namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use App\Comment;

use Redirect, Input;

class CommentsController extends Controller {

	public function index()
	{
		return view('admin.comments.index')->withComments(Comment::all());
	}

	public function edit($id)
	{
		return view('admin.comments.edit')->withComment(Comment::find($id));
	}

	public function update(Request $request, $id)
	{
		$this->validate($request, [
			'nickname' => 'required',
			'content' => 'required',
		]);
		if (Comment::where('id', $id)->update(Input::except(['_method', '_token']))) {
			return Redirect::to('admin/comments');
		} else {
			return Redirect::back()->withInput()->withErrors('更新失败!');
		}
	}

	public function destroy($id)
	{
		$comment = Comment::find($id);
		$comment->delete();

		return Redirect::to('admin/comments');
	}

}

接下来创建两个视图:

learnlaravel5/resources/views/admin/comments/index.blade.php:

@extends('app')

@section('content')
<div class="container">
  <div class="row">
    <div class="col-md-10 col-md-offset-1">
      <div class="panel panel-default">
        <div class="panel-heading">管理评论</div>

        <div class="panel-body">

        <table class="table table-striped">
          <tr class="row">
            <th class="col-lg-4">Content</th>
            <th class="col-lg-2">User</th>
            <th class="col-lg-4">Page</th>
            <th class="col-lg-1">编辑</th>
            <th class="col-lg-1">删除</th>
          </tr>
          @foreach ($comments as $comment)
            <tr class="row">
              <td class="col-lg-6">
                {{ $comment->content }}
              </td>
              <td class="col-lg-2">
                @if ($comment->website)
                  <a href="{{ $comment->website }}">
                    <h4>{{ $comment->nickname }}</h4>
                  </a>
                @else
                  <h3>{{ $comment->nickname }}</h3>
                @endif
                {{ $comment->email }}
              </td>
              <td class="col-lg-4">
                <a href="{{ URL('pages/'.$comment->page_id) }}" target="_blank">
                  {{ App\Page::find($comment->page_id)->title }}
                </a>
              </td>
              <td class="col-lg-1">
                <a href="{{ URL('admin/comments/'.$comment->id.'/edit') }}" class="btn btn-success">编辑</a>
              </td>
              <td class="col-lg-1">
                <form action="{{ URL('admin/comments/'.$comment->id) }}" method="POST" style="display: inline;">
                  <input name="_method" type="hidden" value="DELETE">
                  <input type="hidden" name="_token" value="{{ csrf_token() }}">
                  <button type="submit" class="btn btn-danger">删除</button>
                </form>
              </td>
            </tr>
          @endforeach
        </table>


        </div>
      </div>
    </div>
  </div>
</div>
@endsection

learnlaravel5/resources/views/admin/comments/edit.blade.php:

@extends('app')

@section('content')
<div class="container">
  <div class="row">
    <div class="col-md-10 col-md-offset-1">
      <div class="panel panel-default">
        <div class="panel-heading">编辑评论</div>

        <div class="panel-body">

          @if (count($errors) > 0)
            <div class="alert alert-danger">
              <strong>Whoops!</strong> There were some problems with your input.<br><br>
              <ul>
                @foreach ($errors->all() as $error)
                  <li>{{ $error }}</li>
                @endforeach
              </ul>
            </div>
          @endif

          <form action="{{ URL('admin/comments/'.$comment->id) }}" method="POST">
            <input name="_method" type="hidden" value="PUT">
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <input type="hidden" name="page_id" value="{{ $comment->page_id }}">
            Nickname: <input type="text" name="nickname" class="form-control" required="required" value="{{ $comment->nickname }}">
            <br>
            Email:
            <input type="text" name="email" class="form-control" required="required" value="{{ $comment->email }}">
            <br>
            Website:
            <input type="text" name="website" class="form-control" required="required" value="{{ $comment->website }}">
            <br>
            Content:
            <textarea name="content" rows="10" class="form-control" required="required">{{ $comment->content }}</textarea>
            <br>
            <button class="btn btn-lg btn-info">提交修改</button>
          </form>

        </div>
      </div>
    </div>
  </div>
</div>
@endsection

后台管理功能完成,查看效果:

Image


Image

6. 大作业

依赖于 Page 的评论功能已经全部完成,个人博客系统雏形诞生。在本系列教程的最后,布置一个大作业:构建出 Article 的前后台,并且加上 Article 与 Comment 的一对多关系,加入评论和评论管理功能。在做这个大作业的过程中,你将会反复地回头去看前面的教程,反复地阅读中文文档,会仔细阅读我的代码,等你完成大作业的时候,Laravel 5 就真正入门啦~~


教程(四)代码快照:https://github.com/johnlui/Learn-Laravel-5/archive/tutorial_4.zip


Laravel 5 系列入门教程【最适合中国人的 Laravel 教程】到此结束,谢谢大家!

WRITTEN BY

avatar
2015.3.11   /   热度:59728   /   分类: Laravel

评论:

harthali
2017-08-07 10:20
可以 非常有用
幸运儿
2017-03-17 17:55
你好,我们在使用laravel自带的登录注册的时候,登录注册后,它是直接跳转到home路由的。可是我们争产过的逻辑应该是跳转到登录之前的页面才是啊。很多教材都没有解决这个问题,也都忽略了这个问题。我的思路是在 return view('auth.login')之前给它一个session记录跳转到这个页面之前的路由,登录之后,跳转到这个路由。可是我测试不通。好像中间有什么过程会把我保存的这个session清除掉。请问您有什么好的办法解决吗?谢谢
hhhh
2017-03-12 18:43
教程可以
what!!!!
2016-10-11 17:35
老是救命啊  为什么我 “后台首页”和“管理评论”的两个连接点击后URL中没有index.php导致找不到地址无法显示。。路由器中如何修改呢
岁寒大宝宝
2016-07-22 18:12
岁寒你好,我想深入学习laravel,但是看了几天源码,发现根本摸不着头脑啊,请问你有好的建议吗?
蓝海
2016-05-26 13:32
大神,你好,我在写前端评论时也遇到了这个问题
Whoops, looks like something went wrong.

2/2
ErrorException in d70faa19897442d1f6c5b0fe0fe9864dbf3a4e7d.php line 39:
Invalid argument supplied for foreach()

查看前台评论时说foreach 的参数无效。。但是存在数据库里了啊。。
蓝海
2016-05-25 10:20
大神,请问if (Comment::create(Input::all()))是什么意思啊?
xl
2016-07-15 19:45
@蓝海:看看模型ORM可以知道
chrysalis
2016-05-19 21:42
请问控制器的头部引入的 use Redirect, Input; 这些叫什么?如果没有引入这两个的话用什么来代替redirect?
我知道input可以用request->input()来代替。
drummer30
2016-04-27 17:50
Whoops, looks like something went wrong.

2/2
ErrorException in 9fcc595248053b91450538bd5aa0cdfe line 64:
Invalid argument supplied for foreach() (View: D:\WWW\laravel3\resources\views\pages\show.blade.php)

大神,我是跟着你那个这个:
                                                 前台评论功能完成。
                                                 查看效果:
这打开页面后报错说foreach 的参数无效,前面的步骤都对,我没找到原因
drummer30
2016-04-27 19:05
@drummer30:找到原因了
蓝海
2016-05-25 11:19
@drummer30:求问什么原因??
gray code
2016-04-13 15:18
非常感谢楼主的贡献! 受益匪浅
Carrie
2016-03-20 16:09
Class 'input' not found
之前一直都是把改为request了,但是Input::except(), Input::all()很好用的样子,查了下
发现5.2的版本需要在config/app.php手动添加
'Input' => Illuminate\Support\Facades\Input::class,

然后 use Input;
OpenHair
2016-03-17 16:17
我靠 楼主好厉害   求带。
跟这脚步把些入门都搞完了。 哈哈
xue
2016-03-05 12:22
为什么没办法注册账号呢

错误信息
Sorry, the page you are looking for could not be found.

1/1
NotFoundHttpException in RouteCollection.php line 145:
in RouteCollection.php line 145
at RouteCollection->match(object(Request)) in Router.php line 719
at Router->findRoute(object(Request)) in Router.php line 642
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
wyb007
2016-04-01 15:06
@xue:你的resources/views中没有register的代码吧?
key
2017-07-13 10:47
@wyb007:如何添加register的代码。。。
xue
2016-03-05 11:22
前台列表也无法进入详情页面,是什么原因
Whoops, looks like something went wrong.

1/1
ReflectionException in Container.php line 776:
Class App\Http\Controllers\PagesController does not exist
in Container.php line 776
at ReflectionClass->__construct('App\Http\Controllers\PagesController') in Container.php line 776
at Container->build('App\Http\Controllers\PagesController', array()) in Container.php line 656
at Container->make('App\Http\Controllers\PagesController', array()) in Application.php line 613
at Application->make('App\Http\Controllers\PagesController') in ControllerDispatcher.php line 83
at ControllerDispatcher->makeController('App\Http\Controllers\PagesController') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\PagesController', 'show') in Route.php line 198
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
at Route->run(object(Request)) in Router.php line 691
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 693
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
JohnLui
2016-03-05 11:23
@xue:Class App\Http\Controllers\PagesController does not exist
xue
2016-03-05 11:36
@JohnLui:,好了。不过提交评论以后。数据库只保存了content和时间,没有姓名。这是怎么回事
yankeys
2016-06-30 18:33
@xue:白名单。。。。。我也曾经马虎过,,哈哈哈

2016-02-24 10:28
错误信息:
QueryException in Connection.php line 620:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '/admin/comments/1' in 'field list' (SQL: update `comments` set `page_id` = 12, `nickname` = 旺, `email` = 497580157@qq.com, `website` = www.wang.com, `content` = 这文章很不错111, `/admin/comments/1` = , `updated_at` = 2016-02-24 10:27:55 where `id` = 1)

代码:
public function update(Request $request, $id)
    {
        $this->validate($request, [
            'nickname'    => 'required',
            'content'    => 'required',
        ]);

        if(Comment::where('id', $id)->update(Input::except(['_method', '_token']))){
            return Redirect::to('admin/comments');
        } else {
            return Redirect::back()->withInput()->withErrors('更新失败!');
        }
    }


也不知道是哪里错了,复制楼主你的代码到我那也不行,求解
JohnLui
2016-02-24 10:32
@旺:Input::all() 里多了一个键叫“/admin/comments/1”,值为空,非常奇怪。

2016-02-24 10:41
@JohnLui:这是我打印出来的$_POST数组
array(7) {
  ["_method"]=>
  string(3) "PUT"
  ["_token"]=>
  string(40) "9483YWH5bLgGQ3soae7aUcFHaG5mss5bKP6jtquL"
  ["page_id"]=>
  string(2) "12"
  ["nickname"]=>
  string(3) "旺"
  ["email"]=>
  string(16) "497580157@qq.com"
  ["website"]=>
  string(12) "www.wang.com"
  ["content"]=>
  string(21) "这文章很不错111"
}

这是我的html代码,都没有呀,555555555
<form action="{{ URL('admin/comments/'.$comment->id) }}" method="POST">
                        <input name="_method" type="hidden" value="PUT">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="page_id" value="{{ $comment->page_id }}">
                        Nickname: <input type="text" name="nickname" class="form-control" required="required" value="{{ $comment->nickname }}">
                        <br>
                        Email:<input type="text" name="email" class="form-control" required="required" value="{{ $comment->email }}">
                        <br>
                        Website:<input type="text" name="website" class="form-control" required="required" value="{{ $comment->website }}">
                        <br>
                        Content:<textarea name="content" rows="10" class="form-control" required="required">{{ $comment->content }}</textarea>
                        <br>
                        <button class="btn btn-lg btn-info">提交修改</button>

                    </form>

2016-02-24 10:44
@JohnLui:楼主,我打印$_GET
array(1) {
  ["/admin/comments/1"]=>
  string(0) ""
}

有这个,但是我按照你的写,为啥下面的语句会把$_GET的也加到更新语句里,难道是我nginx里加了个重写导致的?我隐藏了index.php,把所有的参数都重写到index.php?$1里了,可能是这里,下面的语句有没有办法改成只把$_POST的数组添加进更新语句,麻烦求解
if(Comment::where('id', $id)->update(Input::except(['_method', '_token']))){
            return Redirect::to('admin/comments');
        } else {
            return Redirect::back()->withInput()->withErrors('更新失败!');
        }

2016-02-24 11:07
@旺:楼主问题已解决了,但是我还是要说出来一下,嘿嘿
找了下官方的laravel配置,
Nginx

在 Nginx,在你的网站配置中增加下面的配置,可以使用「优雅链接」:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

然后在我的nginx配置中加了这个,就没有问题了,谢谢楼主的查阅

2016-07-15 14:51
@旺:我遇到的问题和你一样,也像你说的那样改,但是还是没有解决!怎么办?
酒窝
2016-02-02 21:10
谢谢撸主,通俗易懂
csdc
2016-01-12 22:40
厉害厉害
雪域
2016-01-05 18:20
头大了一下午了,我想重写它的登录注册系统,一开始很顺利,没有用model,直接在control里写的db查询,但是session怎么也写不进去,用了无数种方法,然后跟着教程来了一遍,发现它的compiled文件里生成session都成功了,然后我的编辑器就报很多错,然后这个文件居然有17162行,这正常吗?然后我写在新建博客的控制器里写了插入session的语句,但是session文件显示的更新时间变了,但我的session变量还是没有存进去,难受!
willdoge
2015-12-28 15:42
大神 请教个问题 一直没有明白呢~为什么在更新数据库失败后返回前页还带着withInput()?
JohnLui
2015-12-28 23:53
@willdoge:把用户输入的数据带回去,让他们直接修改而不需要重新输入。
alex
2015-12-27 16:21
我解决样式问题了,是因为我的default.blade.php界面用的是自己找的ui代码,没有加载成功css文件导致的

发表评论:

© 2011-2017 岁寒  |  Powered by Emlog