1.安装composer。直接下载Composer-Setup.exe默认安装
2.composer ok 之后;进入cmd ,切换到你需要放置laravel的路径下,输入:
composer create-project laravel/laravel --prefer-dist
3.等待安装完成。。。要个十几分钟的
4.ok之后,你跑到你刚刚切换的路径下去看 就能发个一个完整的laravel文件在哪里 一动不动 哈哈哈哈。。。。。。
5.在vendor查看了框架的版本:Laravel5.4。找呀找呀找文档。。。。。。(https://laravel.com/docs/5.4)
6.看不下去了 (我很想知道怎么才能出来一个页面),算了!先尝试一个 hello world吧 (默默的找度娘去了);看不懂英文文档的,不要浪费时间去找翻译了,给你个中文文档的链接(http://laravelacademy.org/post/6947.html)
7.我本地服务器 用的 apache 需要在配置文件里 打开 这一行: LoadModule rewrite_module modules/mod_rewrite.so(URL重写)
8.上一步只是给第一次装环境的人看的,接着把localhost的路径直接指定到laravel的public目录下:(因为laravel只对外开放public目录,现在问我为什么,我也不知道)(在wamp目录下的conf/extra/httpd-vhosts.conf,修改DocumentRoot后的路径,同时AllowOverride后面为all),然后你在浏览器输入localhost按一下enter键:
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www/laravel/public
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
9.浏览出来的是这个,hello world 已经离我们很近了!!!!。
10.咳咳。。。 hello world来了 。。。。。。
11.第一步 直接找到。。。 诶呀啊啊。。。 怎么弄不出来。。。
一番斗争之后。。。(学习的时候还是应该认真看文档的)
12.找到routes/web.php,根据文档描述的修改一下下。
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/hello', function()
{
return "Hello World!";
});
13.好了,在浏览器里面输入localhost/hello;
em……
14.出来是出来了,但这只是个开始!下一步,如何从控制器里显示出来。。。
15.先定义路由;
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
// Route::get('/hello', function()
// {
// return "Hello World!";
// });
Route::get('/hello', 'Hello@index');
//Hello是控制器的名字 index对应到的方法
16.找到app/Http/Controllers建一个控制器文件:Hello.php(目测lv的控制器命名这样写也是木有问题的)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class Hello extends Controller
{
public function index()
{
return 'Hello World!';
//第一个info就是key,第二个就是值上面的$info,这样这个值就可以显示在index.blade.php里面了;如果views里面你还有一层文件夹index那就写成view('index.index');
}
}
刷新页面
啦啦啦。。。
17.控制器找到了,该找view了。先修改控制器的代码;
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class Hello extends Controller
{
public function index()
{
$info='Hello World!';
return view('index')->with('info',$info);
//第一个info就是key,第二个就是值上面的$info,这样这个值就可以显示在index.blade.php里面了;如果views里面你还有一层文件夹index那就写成view('index.index');
}
}
18.resources/views/下建一个index.blade.php
{{ $info }}
刷新一下页面;你会发现还是一开始的样子!!!!
19.就这么多了。
欢迎关注我的个人公众号,上面更新一些我的学习笔记,你也可以在后台问我