如何在 Laravel 5.1 中使用 Laravel Elixir 集成安装laravel bootstrapp

laravel 5.1版本 如何动态的引入 CSS JS 代码?
目前使用的方法是&link rel="stylesheet" href="/question/{{ URL::asset('/') }}css/bootstrap.min.css"&
请问还有没有其他更好的办法了~~~~~~~~~~~~~~~~~~~~~~~~~~~~网友回复:
【laravel 5.1版本 如何动态的引入 CSS JS 代码?】
请将本文分享给你的朋友:
laravel 5.1版本 如何动态的引入 CSS JS 代码? 的相关文章
------分隔线----------------------------
北京联盟郑重声明:本文仅代表作者个人观点,与北京联盟无关。其原创性及文中陈述内容未经本站证实,北京联盟对本文及其中全部或者部分内容的真实性、完整性、及时性不作任何保证和承诺,请网友自行核实相关内容。安装 Laravel 5 的时候,默认的已经带了一套用户认证系统,我们可以在 routes.php 中看到下面的代码(如果你之前删除了,请添加上):
Route::controllers([
'auth' =& 'Auth\AuthController',
'password' =& 'Auth\PasswordController',
上面使用了 Route::controllers() 方法来创建路由,但这种方法非常不推荐大家使用。上面两个分别是用于 认证(auth) 和 重置密码(password) 的。
两个文件分别为 app\Http\Controllers\Auth\AuthController.php 和 app\Http\Controllers\Auth\PasswordController.php。详细代码自己查看文件内容,实现代码其实在文件 vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers.php 中。
在命令行输入下面的命令查看所有路由:
D:\wamp\www\laravel5&php artisan route:list
可以看到现在多出了认证与密码重置的相关路由。
由于前一节我们通过命令行 tinker 添加了一些数据,所有在进行今天的操作之前先把数据库重置一下:
D:\wamp\www\laravel5&php artisan migrate:refresh
现在数据库已经回复,我们来进行用户注册。浏览器打开 http://laravel.dev/auth/register ,可以看到,这个就是 Laravel 5 自带的用户注册界面。我们输入用户名、邮箱及密码注册第一个用户。
注册之后我们发现页面跳转到 http://laravel.dev/home ,如果你的 routes.php 中删除了 Route::get('home', 'HomeController@index'); 请添加回去,否则会出现一个错误提示页面。
现在可以看到,Laravel 提示我们已经登录成功。退出系统可以使用右上角的退出链接,或者直接浏览器输入 http://laravel.dev/auth/logout。
在 ArticlesController.php 的 index() 方法中的第一行添加代码:return \Auth::user(); ,然后浏览器访问 http://laravel.dev/articles ,页面返回一个 JSON 格式的用回信息:
也可以使用 return \Auth::user()-& 返回用户名,而当我们退出系统再访问的时候,会提示我们 “Trying to get property of non-object”,这是因为 \Auth::user() 的结果是 null,我们不能返回 null-&name 的值。现在到页面 http://laravel.dev/auth/login 使用刚才注册的用户名密码进行登录,否则后面的操作会出错。
打开resources\views\articles\_form.blade.php 找到之前我们添加的代码 {!! Form::hidden('user_id', 1) !!} ,并把它去掉保存,因为这里我们不再需要通过表单隐藏域来设置关联用户了。
之后修改 Article 控制器中的 store() 方法:
public function store(ArticleRequest $request){
$article = new Article($request-&all());
\Auth::user()-&articles()-&save($article);
return redirect('articles');
上面的方法会自动关联用户的ID,这是因为我们在 app\User.php 模型中定义了:
public function articles(){
return $this-&hasMany('App\Article');
现在到浏览器访问 http://laravel.dev/articles/create,添加一篇新的文章。之后使用数据库管理工具如 phpmyadmin 查看 articles 表,可以看到文章已经成功的关联了当前登录用户的ID。也可以通过命令行使用 tinker 查看。
D:\wamp\www\laravel5&php artisan tinker
Psy Shell v0.4.1 (PHP 5.5.12 Γ?? cli) by Justin Hileman
&&& App\Article::first()-&toArray();
=& "New Article",
=& "New Body",
"created_at"
=& " 22:41:16",
"updated_at"
=& " 22:41:16",
"published_at" =& " 00:00:00",
&&& $user = App\User::where('name', 'Specs')-&first();
=& &App\User #4d369784& {
name: "Specs",
email: "",
created_at: " 21:52:26",
updated_at: " 22:03:42"
&&& $user-&articles-&toArray();
=& "New Article",
=& "New Body",
"created_at"
=& " 22:41:16",
"updated_at"
=& " 22:41:16",
"published_at" =& " 00:00:00",
&&& $article = new App\Article(['title' =& 'New', 'body' =& 'new body', 'published_at' =& Carbon\Carbon::now()]);
=& &App\Article #4d369784& {
title: "New",
body: "new body",
published_at: &Carbon\Carbon #4d366dc4& {
date: " 22:51:21",
timezone_type: 2,
timezone: "PRC"
&&& $user-&articles()-&save($article);
=& &App\Article #4d369784& {
title: "New",
body: "new body",
published_at: &Carbon\Carbon #4d366dc4& {
date: " 22:51:21",
timezone_type: 2,
timezone: "PRC"
user_id: 1,
updated_at: " 22:52:02",
created_at: " 22:52:02",
本节就这些,下一节介绍中间件(Middleware)。
该篇属于专题:《》下一篇:《》上一篇:《》laravel5._oauth_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
laravel5._oauth
上传于||暂无简介
阅读已结束,如果下载本文需要使用
想免费下载本文?
下载文档到电脑,查找使用更方便
还剩7页未读,继续阅读
你可能喜欢Curated by
Taylor Otwell said that Laravel 4.3 would be renamed to Laravel 5 to reflect a directory change and “other interesting initiatives”. Since that announcement the excitement for Laravel 5 has been building and “other interesting initiatives” turned into almost two dozen new features to help developers be more productive.
and sat on the sidelines waiting patiently. Others dove in and have been using the develop branch for months, painstakingly looking through commits finding breaking changes.
But all of this is coming to end as Laravel just announced that Laravel 5 will be official next week.
#L5. Next week. —
Those three words generated a lot of excitement, and for good reason. Months of time and hard work have been put into this version and it’s finally ready for the world.
Laravel 5 is a substantial upgrade with lots of new toys, but at the same time it keeps the parts that made Laravel wildly successful.
In fact there have been so many new features that it’s hard to keep track of just what all is new. In this post I’ll outline the new features and what you have to look forward to next week.
Laravel 5 Directory Structure
The first major change is with the directory structure. The app folder received a facelift and some things got moved outside app. This includes config, database, storage, and resources.
Inside app things are now broken down into further folders including:
Exceptions
If you are comfortable with previous versions of Laravel this may catch you off guard, but I assure you after about two days of usage it all becomes clear and easy to work with. For more information check out
by Matt Stauffer.
Blade Changes
Blade didn’t get a whole lot of improvements, but one
is pretty substantial for upgrading.
In Laravel 4 Blade included the following two styles: {{ and {{{.
The double curly bracket was a raw echo and the triple curly bracket escaped.
Now both the double and triple curly brackets escape the variable and
a new {!! $var !!} is for raw.
A common use case for raw is with form helpers:
{!! Form::open() !!}
Contracts are a set of interfaces that define the core services provided by the framework. At it’s basics this serves as documentation to the framework’s features. However, they are much more beneficial and you can see the
for more information on these and how they can help.
Commands & Events
Commands and events received a makeover. This feature has been heavily covered both in the
and from the following resources:
Facades and Helpers
Facades are still in Laravel 5, but new helper functions are starting to replace some of the most common items. For example in Laravel 4 to render a view you would use code like this:
View::make('path.to.view');
This is now a simple function call:
view('path.to.view');
Some others are:
* action()
* app_path()
* Routing – get(), delete(), put()
* redirect()
* response()
* and many more…
Routes received two new features.
Matt did such a great job covering both of these topics I can’t really add anything more. Check out his posts for an in-depth look at both.
Controller Method Injection
Laravel 4 supported controller constructor injection. Now this has been taken a step further and you can type-hint any dependencies in your methods:
public function store(Request $request)
or really anything:
public function taxes(TaxCalculator $tax)
Here are some links to go more in depth.
Authentication Scaffolding
A default authentication flow is pre setup and ready for you. Jump starting all this is easier than ever.
This introduces two new traits:
AuthenticatesAndRegistersUsers
ResetsPasswords
The beauty in this is you can use the included or over ride any of the traits methods to customize to your own app.
Laravel Socialite is an optional, Laravel 5.0 package that makes dealing with OAuth easier. Something we all hate right? Currently, Socialite supports Facebook, Twitter, Google, and GitHub.
have more information on implementation and flow.
The next great new feature is the inclusion of Frank de Jonge’s . If you are not familiar with this package it is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.
The current included adapters are:
Amazon Web Services – S3
Rackspace Cloud Files
This means you will easily be able to push file uploads to any of these services and use external storage easier than ever before. For most apps I think this alone is going to be a huge time saver.
dotenv – Environmental Detection
Vance Lucas created a PHP package named
that loads environment variables from a .env to getenv(), $_ENV and $_SERVER automagically.
Laravel 5 includes this package to make managing environments much simpler. No more having to edit the bootstrap/start.php and customizing the $app-&detectEnvironment() array.
Instead you create your own .env file and can easily customize it to suit your needs. Then in any config files you can use something like:
'database' =& env('DB_DATABASE’, 'myproddb'),
You can also create custom ones for different environments such as with testing. In fact Laracasts has a sample
already utilizing this.
Form Requests
Form validation and requests have been talked about a lot and this is one area I’m sure you’ve heard mentioned.
Basically auth and validation can be turned into FormRequests and injected easily.
Check out the following two resources for more information on this feature:
Laravel Elixir
Elixir is a new wrapper around gulp to make dealing with assets easier. Instead of having to hunt around to build your own css and js build system you can use Elixir and be up and running easily.
Out of the box it handles 90% of everything you need: sass, less, coffeescript, JavaScript, file versioning, and many other features.
Laravel Scheduler
is designed to simplify tasks that need to be ran via CRON. All that is required is setting up one cron job that calls artisan schedule:run and have it scheduled every minute.
Once your cron is setup you can schedule any task to run in a concise and friendly manner. It takes the pain out of having to remember cron scheduling and is really simple. These schedules are created inside your “app/Console/Commands” directory.
Here is an example task:
$schedule-&command('cache:clear')
-&hourly()
-&sendOutputTo($filePath)
-&emailOutputTo('');
When this feature was announced it received a lot of mixed reactions. I’m in the camp that it’s brilliant. I like that the cron tasks are versioned, easily viewable in my editor, and above all, written in plain English.
$schedule-&call('SomeClass@method')-&dailyAt('10:00');
Everyone’s favorite function dd(), or dump and die, got a big upgrade. Symfony released a VarDumper Component and Laravel now uses this under the hood.
The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. Built on top, it provides a better dump() function that you can use instead of var_dump.
Very useful and love how much more power this gives us. For more information see .
Eloquent Attribute Casting
This feature comes to us thanks to .
allows you to convert attributes to another data-type. As an example in your model you add a casts property:
protected $casts = [
'is_admin' =& 'boolean',
'options' =& 'array',
This will automatically cast is_admin to a bool. Options would be stored as json and automatically converted to an array when coming out.
This is brilliant when you are using JavaScript and needing to match them up.
Whoops no more
Laravel 4 featured an error handler named Whoops. This has been removed from Laravel 5 but if you want it back see .
Packages and Workbench
The Laravel package system has some substantial changes. The most notable is Workbench is now removed in favor of just using Composer packages directly.
You can find out more about the specific changes around these in the
and a from a tutorial by John in ‘t Hout,
Laravel Psysh
Tinker, the CLI tool to play around with your code, now is using
by Justin Hileman. For those not familiar Psysh is:
A runtime developer console, interactive debugger and REPL —Read-Eval-Print Loop— for PHP
Psysh is super powerful, here is some of the features:
Read documentation in context. doc dd
The list command knows all about your code — and everyone else’s. Easily list and search all variables, constants, classes, interfaces, traits, functions, methods and properties.
Easily show the source code for any userland object, class, interface, trait, constant, method or property.
Catches the last exception and is available via a wtf command.
Show, search, save and replay your shell history.
I’m sure it does much more and will be a great tool in your arsenal.
SuperClosure
, a library for serializing closures and anonymous functions by Jeremy Lindblom, is also a new feature. Under the hood this is being used by the .
New Generators
Artisan is now even more powerful and can generate a lot of boilerplate for you. Here is a list of some of the ones available now:
make:command — Create a new command class
make:console — Create a new Artisan command
make:controller — Create a new resource controller class
make:event — Create a new event class
make:middleware — Create a new middleware class
make:migration — Create a new migration file
make:model — Create a new Eloquent model class
make:provider — Create a new service provider class
make:request — Create a new form request class
event:generate — Generate the missing events and handlers
Upgrading is not going to be a simple composer update. As this is a major version you should expect to spend a few hours getting everything updated. Two guides have already been written to help you in the process. The
Where to go next?
As with any framework the best place to go to learn more is the official documentation. After that subscribe to the
which will keep you up to date on the latest , , and everything else related to Laravel.
2015 is going to be exciting year in the Laravel world and I’m looking forward to keeping you up to date!
Written By
About Eric L. Barnes
Eric is a product engineer and the creator of Laravel News.
Follow Eric L. Barnes:
ShareLike this:Like Loading...
Get your free e-book!
Join over 11,300 smart developers and subscribe to the weekly . By subscribing you'll get a complimentary
and receive Laravel tips, tutorials, and packages delivered right to your inbox.
Hand Crafted & Delivered every Sunday.
– Recent Posts –
– Most Read –
Search the Archives
& 2012 - 2015 Laravel News - by
Don't Miss the Sunday Digest
Join 6,500+ developers and get the weekly newsletter that includes Laravel tips, tutorials, packages, and other goodies.
%d bloggers like this:

我要回帖

更多关于 django 集成bootstrap 的文章

 

随机推荐