- laravel Mix
- 使用larave mix时,npm run dev 报“cross-env 不是内部命令”的错误
- laravel blades
- 报错require(vendor/autoload.php): failed to open stream
- 资源控制器
- Laravel 5 clear views cache
- 返回404页面
- Vue packages version mismatch: - vue@2.5.16 - vue-template-compiler@2.5.17
- Vue js unknown custom element
- Bootstrap pull-right not working as expected
- creates the model, a migration file and a resource controller simultaneously
- What is ::class in PHP?
- validation
laravel Mix
使用larave mix时,npm run dev 报“cross-env 不是内部命令”的错误
You need to make cross-env working globally instead of having it in the project.
1) remove node_modules folder
2) run
npm install —global cross-env
3) remove "cross-env": "^5.0.1", from package.json file devDependencies section. Actually, you can skip this step and keep package.json intact. If you prefer.
4) run
npm install —no-bin-links
5) run
npm run dev
and see it working
P.S Tested on Windows 10 with Laravel-5.4
P.P.S Windows 10 with Laravel-5.6 does not have this problem, thus updating is an alternative solution.
来源:https://stackoverflow.com/questions/34840653/cannot-make-bootstrap-work-with-webpack
laravel blades
layout\master.blade.php
...<div class="w3l_banner_nav_right">@yield('content')</div>...
index.blade.php
@extends('layout.master')@section('content')<section class="slider"><div class="flexslider"><ul class="slides"><li><div class="w3l_banner_nav_right_banner"><h3>Make your <span>food</span> with Spicy.</h3><div class="more"><a href="products.html" class="button--saqui button--round-l button--text-thick" data-text="Shop now">Shop now</a></div></div></li><li><div class="w3l_banner_nav_right_banner1"><h3>Make your <span>food</span> with Spicy.</h3><div class="more"><a href="products.html" class="button--saqui button--round-l button--text-thick" data-text="Shop now">Shop now</a></div></div></li><li><div class="w3l_banner_nav_right_banner2"><h3>upto <i>50%</i> off.</h3><div class="more"><a href="products.html" class="button--saqui button--round-l button--text-thick" data-text="Shop now">Shop now</a></div></div></li></ul></div></section>@stop
顶部的 @extends('layout.master') 表明 index.blade.php 继承放在 layout 目录下的 master.blade.php 父类,接下来一行 @section('content') 定义一个块名为 content 的内容, yield('content') 来呈现。 @stop 表明在这里停止。
报错require(vendor/autoload.php): failed to open stream
报错信息:
Warning: require(D:\phpStudy\PHPTutorial\WWW\dexmarket\public/../vendor/autoload.php): failed to open stream: No such file or directory in D:\phpStudy\PHPTutorial\WWW\dexmarket\public\index.php on line 24
Fatal error: require(): Failed opening required ‘D:\phpStudy\PHPTutorial\WWW\dexmarket\public/../vendor/autoload.php’ (include_path=’.;C:\php\pear’) in D:\phpStudy\PHPTutorial\WWW\dexmarket\public\index.php on line 24
解决:
What you’re missing is running composer install, which will import your packages and create the vendor folder, along with the autoload script.
Make sure your relative path is correct. For example the example scripts in PHPMailer are in examples/, below the project root, so the correct relative path to load the composer autoloader from there would be ../vendor/autoload.php.
The autoload.php you found in C:\Windows\SysWOW64\vendor\autoload.php is probably a global composer installation - where you’ll usually put things like phpcs, phpunit, phpmd etc.
来源 :https://stackoverflow.com/questions/41209349/requirevendor-autoload-php-failed-to-open-stream
资源控制器
创建一个资源控制器php artisan make:controller ProductController --resource
It is a special type of controller which contains all methods can be performed with a model like GET , POST , DELETE , PUT etc.
When you run the command it will create the controller with methods like index() , create() etc.
路由设置
Since the controller is a Resourceful Controller we will not need to create separate routes for each method. Instead I am going to do the following in routes/web.php file:Route::resource('product', 'ProductController')
run php artisan route:list something like below will appear :
+--------+-----------+-------------------------------+-----------------+-----------------------------------------------------+--------------+| Domain | Method | URI | Name | Action | Middleware |+--------+-----------+-------------------------------+-----------------+-----------------------------------------------------+--------------+| | GET|HEAD | / | | App\Http\Controllers\HomeController@index | web || | GET|HEAD | _dusk/login/{userId}/{guard?} | | Laravel\Dusk\Http\Controllers\UserController@login | web || | GET|HEAD | _dusk/logout/{guard?} | | Laravel\Dusk\Http\Controllers\UserController@logout | web || | GET|HEAD | _dusk/user/{guard?} | | Laravel\Dusk\Http\Controllers\UserController@user | web || | GET|HEAD | api/user | | Closure | api,auth:api || | GET|HEAD | product | product.index | App\Http\Controllers\ProductController@index | web || | POST | product | product.store | App\Http\Controllers\ProductController@store | web || | GET|HEAD | product/create | product.create | App\Http\Controllers\ProductController@create | web || | GET|HEAD | product/{product} | product.show | App\Http\Controllers\ProductController@show | web || | PUT|PATCH | product/{product} | product.update | App\Http\Controllers\ProductController@update | web || | DELETE | product/{product} | product.destroy | App\Http\Controllers\ProductController@destroy | web || | GET|HEAD | product/{product}/edit | product.edit | App\Http\Controllers\ProductController@edit | web |+--------+-----------+-------------------------------+-----------------+-----------------------------------------------------+--------------+
Laravel itself took care of the necessary routes and created named routes. For instance product.create can be referred when we are going to add a product by calling create method of ProductController.
Laravel 5 clear views cache
php artisan view:clear
返回404页面
you may use the abort helper:
abort(404);
来源: https://www.codementor.io/pknerd/posts
Vue packages version mismatch: - vue@2.5.16 - vue-template-compiler@2.5.17
By removing and adding again; solved my problem.npm remove vuenpm audit fix --forcenpm add vue --save
来源:https://github.com/nblackburn/vue-brunch/issues/37
Vue js unknown custom element
Just define Vue.component() before new vue().
Vue.component('my-task',{
.......
});
new Vue({
.......
});
来源:https://stackoverflow.com/questions/39382032/vue-js-unknown-custom-element
Bootstrap pull-right not working as expected
For those who are using bootstrap4:
classes for responsive floats and removed .pull-left and .pull-right since they’re redundant to .float-left and .float-right.
More information from Bootstrap4 migration notes: Here
来源: https://stackoverflow.com/questions/35036669/bootstrap-pull-right-not-working-as-expected
creates the model, a migration file and a resource controller simultaneously
$ php artisan make:model Task -mr
What is ::class in PHP?
This feature was implemented in PHP 5.5.
Documentation : http://php.net/manual/en/migration55.new-features.php#migration55.new-features.class-name
It’s very useful for 2 reasons.
You don’t have to store your class names in strings anymore. So, many IDEs can retrieve these class names when you refactor your code
You can use the
usekeyword to resolve your class and you don’t need to write the full class name.
For exemple :
use \App\Console\Commands\Inspire;
//...
protected $commands = [
Inspire::class, // Equivalent to "App\Console\Commands\Inspire"
];
Update :
This feature is also useful for Late Static Binding.
Instead of using the __CLASS__ magic constant, you can use the static::class feature to get the name of the derived class inside the parent class. For example:
class A {
public function getClassName(){
return __CLASS__;
}
public function getRealClassName() {
return static::class;
}
}
class B extends A {}
$a = new A;
$b = new B;
echo $a->getClassName(); // A
echo $a->getRealClassName(); // A
echo $b->getClassName(); // A
echo $b->getRealClassName(); // B
https://stackoverflow.com/questions/30770148/what-is-class-in-php
validation
<?php
$messages = [
'enterprise_name.required' => '必填',
'state.required' => '必填',
'industry_id.required' => '必填',
'enterprise_address.required' => '必填',
'charge_name.required' => '必填',
'charge_phone.required' => '必填',
'login_phone.required' => '必填',
'charge_phone.regex' => '手机号不正确',
'login_phone.regex' => '手机号不正确',
'zone_area_id.required' => '必填', // 添加办公区域id
];
$validator = \Validator::make($request->all(), [
'enterprise_name' => 'required|string|max:100',
'state' => 'required|int', //1待执行 2 执行中 3 收铺待结算 4 已收铺
'industry_id' => 'required|int',
'enterprise_address' => 'required|string|max:60',
'charge_name' => 'required|string',
'charge_phone' => 'required|string|max:50|regex:/^1[3456789][0-9]{9}$/',
'login_phone' => 'required|string|max:50|regex:/^1[3456789][0-9]{9}$/',
'zone_array' => 'array',
], $messages);
if ($validator->fails()) {
return response()->json(['s' => 0, 'm' => $this->getErrorBadRequest($validator)]);
}
