切成中文模式
shift+地球 設定文字大小
介紹XY軸背景圖
介紹腳色i
插入腳色
2015年8月5日 星期三
ubuntu伺服器設定
ubuntu 14.04.2
套件
apt-get install apache2 php5 php5-mcrypt mysql-server-5.5 git
appache2 enable rewrite
a2enmod rewrite
apache設定檔
AllowOverride All
網站根目錄laravel/public
/var/www/html
/var/www/laravel/public
ln -s /var/www/laravel/public var/www/html/myapp
http://123.456.789.1/myapp
.env設定要改
套件
apt-get install apache2 php5 php5-mcrypt mysql-server-5.5 git
appache2 enable rewrite
a2enmod rewrite
apache設定檔
AllowOverride All
網站根目錄laravel/public
/var/www/html
/var/www/laravel/public
ln -s /var/www/laravel/public var/www/html/myapp
http://123.456.789.1/myapp
.env設定要改
2015年8月4日 星期二
熱門文章
Route加路徑Route::get('posts/hot', ['as'=>'posts.hot','uses'=>'PostController@hot']);
PostController加hot functionpublic function hot(){ $posts = Post::with('user') ->where('page_views', '>=' , 100) ->orderBy('page_views', 'desc') ->paginate(5) ; //dd($posts); return view('posts.index', compact('posts')); }
nav.blade.php的超連結設定路由
nav.blade.php的超連結設定路由
<a class="navbar-brand" href="{{ route('home.index') }}">我的部落格</a> </div> <div class="navbar-collapse collapse navbar-inverse-collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="{{ route('posts.index') }}"><i class="fa fa-list-ul my-icon"></i> 文章總覽</a></li> <li><a href="{{ route('posts.hot') }}"><i class="fa fa-fire my-icon"></i> 熱門文章</a></li> <li><a href="about.html"><i class="fa fa-info-circle my-icon"></i> 關於本站</a></li> </ul>
route加入hot路由
Route::get('posts/hot', ['as'=>'posts.hot','uses'=>'PostController@hot']);
2015年8月3日 星期一
給route路徑別名
字串變陣列
Route::get('/', PostController@index');
Route::get('posts', 'PostController@index');
Route::get('/posts/{id}', 'PostController@show');
陣列
Route::get('/', ['as'=>'home.index','uses'=>'PostController@index']);Route::get('posts', ['as'=>'post.index','uses'=>'PostController@index']);Route::get('posts/{id}', ['as'=>'post.show','uses'=>'PostController@show']);
index.blade.php
加入超連結
{{ route('posts.show', [$post->id]) }}
文章標題製作超連結可以連結到每篇文章的內容
index.blade.php
<div class="panel panel-default my-article"> <div class="panel-heading"> <h4><a href="{{ url('posts/'.$post->id) }}">{{ $post->id }}{{ $post->title }}</a></h4> </div> <div class="panel-body"> {{ $post->content }} </div> <div class="panel-footer"> 作者: <a href="oneuserposts.html">{{ $post->user->name }}</a> <div class="pull-right"> 發表於: {{ $post->created_at }}</div> <div class="pull-right">觀看次數: {{ $post->page_views }} 次</div> <div class="my-tags"> Tags:<a href="tag-posts.html?tag=1"><span class="tag">標籤1</span></a> <a href="tag-posts.html?tag=2"><span class="tag">標籤tag2</span></a> <a href="tag-posts.html?tag=3"><span class="tag">tag3</span></a> </div> </div> </div>
Route::pattem('id', '[0-9]+
Route的放置順序很重要
id限定格視為數字
//id限制格式Route::pattern('id', '[0-9]+');Route::get('/', 'PostController@index');Route::get('posts', 'PostController@index');Route::get('/posts/{id}', 'PostController@show'); Route::get('/test', function(){ $user = \App\Post::with('user')->find(1); dd($user);});
呈現一篇文章show.blade.php
post.html複製貼到resource/view/posts/show.blade.php中
只留contanter其餘刪除
頭加入
只留contanter其餘刪除
頭加入
@extends('layouts.master') @section('content')
尾加入
@endsection
在原本的nav與footer處加入@include('partials.nav')
@include('partials.footer')
在route.php加入
Route::get('posts', 'PostController@index');Route::get('/posts/{id}', 'PostController@show');postController加入return view('posts.show');public function show($id){return view('posts.show'); }目前呈現的是假資料
在PostController
public function show($id){$post =Post::find($id);return view('posts.show', compact('post'));}
/resource/view/posts/show.blade.php
可呈現資料庫中的文章<div class="panel panel-default"><div class="text-right" style="padding-right: 15px;"> <form action="" method="POST"> <a class="btn btn-material-blue btn-lg" href="editpost.html"><i class="fa fa-edit"></i> 編輯</a><button class="btn btn-danger btn-lg" type="submit"><i class="fa fa-trash"></i> 刪除</button> </form></div> <div class="panel-body"> {!! $post->content !!} </div> <div class="panel-footer"> 作者: <a href="oneuserposts.html">{{ $post->user->name }}</a> <div class="pull-right"> 發表於:{{ $post->created_at }}</div> <div class="pull-right">觀看次數:{{ $post->page_views }} 次</div> </div> </div>
整理程式碼_將route的function拉出去
route的function拉出去
用cmder下建立controller
php artisan make:controller PostController
在App/Http/Controller/資料夾出現PostController.php
將route的function剪下貼在PostController.php
RESTful七個功能
GET /posts 取列表 index()
GEt /posts/id/edit 編輯表單 edit()
POST /posts 新增 store()
GET /posts/id 取一篇文章 show()
GET /post/create 秀出新增表單 create()
PUT/PATCH /posts/id 更新 update()
DELETE /posts/id 刪除 delete()
附註:
php artisan make:controller PostController --plan
空的
用cmder下建立controller
php artisan make:controller PostController
在App/Http/Controller/資料夾出現PostController.php
將route的function剪下貼在PostController.php
RESTful七個功能
GET /posts 取列表 index()
GEt /posts/id/edit 編輯表單 edit()
POST /posts 新增 store()
GET /posts/id 取一篇文章 show()
GET /post/create 秀出新增表單 create()
PUT/PATCH /posts/id 更新 update()
DELETE /posts/id 刪除 delete()
附註:
php artisan make:controller PostController --plan
空的
master.blade.php將js及css由相對路徑改成絕對路徑
html> <html lang="zh-Hant"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}"> <link rel="stylesheet" href="{{ asset('css/font-awesome.min.css') }}"> <link rel="stylesheet" href="{{ asset('css/animate.min.css') }}"> <link rel="stylesheet" href="{{ asset('css/roboto.min.css') }}"> <link rel="stylesheet" href="{{ asset('css/material.min.css') }}"> <link rel="stylesheet" href="{{ asset('css/ripples.min.css') }}"> <link rel="stylesheet" href="{{ asset('css/mycss.css') }}"> <title>我的部落格</title> </head> <body> @include('partials.nav') ( <div class="container"> @yield('content') </div> </div> @include('partials.footer') <script src="{{ asset('js/jquery-2.1.4.min.js') }}"></script> <script src="{{ asset('js/bootstrap.min.js') }}"></script> <script src="{{ asset('js/jquery.bootstrap-autohidingnavbar.min.js') }}"></script> <script src="{{ asset('js/ripples.min.js') }}"></script> <script src="{{ asset('js/material.min.js') }}"></script> <script> $(document).ready(function(){ $.material.init(); }); $('nav').autoHidingNavbar();</script> @yield('extrajs') </body> </html>
整理master.blade.php將nav及footer拉出來
設partials資料夾新增nav.php及footer.php
將master.blade.php中nav和footer資料剪下分別貼在nav.php及footer.php
在master.blade.php中nav位置放
將master.blade.php中nav和footer資料剪下分別貼在nav.php及footer.php
在master.blade.php中nav位置放
@include('partials.nav')
在master.blade.php中footer位置放
@include('partials.footer')
如何減少撈資料庫的次數
Eager Loading
route.php加入with('user')->可以減少撈資料庫的次數
route.php加入with('user')->可以減少撈資料庫的次數
Route::get('/', function () {
$posts = \App\Post::with('user')->;paginate(10);
return view('posts.index', compact('posts'));});
Route::get('/test', function(){ $user = \App\Post::with('user')->find(1); dd($user);});
在route.phpv新增測試用工具可以去資料庫取值localhost:8000/test
在route.phpv新增測試用工具可以去資料庫取值localhost:8000/test
//測試用
Route::get('/test', function(){
$post = \App\Post::find(1);
$user =$post->;user;
dd($user->name);
});
更簡潔的寫法
Route::get('/test', function(){
$user = \App\Post::find(1)->user;
dd($user->name);
});
index.blage.php
作者: <a href="oneuserposts.html">{{ $post->user->name }}</a>
laravel20150804
08
安裝Bebug
composer require barryvdh/laravel-debugbar
composer require guidovanbiemen/laravel-whoops -dev
設定
After updating composer, add the
ServiceProvider to the providers array in config/app.php
'providers' => [
//debugar
Barryvdh\Debugbar\ServiceProvider::class,
Barryvdh\Debugbar\ServiceProvider::class,
'aliases' => [
//debugar 'Debugbar' => Barryvdh\Debugbar\Facade::class,
.env可以關掉debugbar
安裝whoops
Cmder
composer require guidovanbiemen/laravel-whoops
Now go into your
config/app.php
and add the service provider:'Gvb\Whoops\ServiceProvider',
訂閱:
文章 (Atom)