laravel helpers url () introduced js and css static files

When using a static framework laravel files can be as, js files, css files under, under js into the resources folder, of course, you can put public folder js folder, publi folder by default is no css, js, images and other static folders, you need to create your own.

Once created, it can be introduced in view these files, but there are some problems, how to get the relative path of these files.

Why should I get a path relative static files, because in many cases, local development projects, and then migrate to linux server, if the absolute path, such as this:

E:\workspace\laravel\your-project-name\public

Although time may play a role in local development, but on linux to deploy, it will cause a lot of trouble.

In Laravel, helper functions provided, the public_path()function will generate a similar file path

Fortunately, however, laravel also provides a url()function to generate relative path

Using a similar method the following frame in the template file can be introduced in the public directory js, and css

<link rel="stylesheet" href="{{url('/')}}/css/admin/admin.css">
<script src="{{url('/')}}/layui/layui.js"></script>

Finally, after parsed the following content


<link rel="stylesheet" href="http://www.laravel.com/css/admin/admin.css">
<script src="http://www.laravel.com/layui/layui.js"></script>

If the url()function is changed to secure_url()function will generate https protocol


<link rel="stylesheet" href="https://www.laravel.com/css/admin/admin.css">
<script src="https://www.laravel.com/layui/layui.js"></script>

Guess you like

Origin www.cnblogs.com/zxcv123/p/11967100.html