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

  1. ...
  2. <div class="w3l_banner_nav_right">
  3. @yield('content')
  4. </div>
  5. ...

index.blade.php

  1. @extends('layout.master')
  2. @section('content')
  3. <section class="slider">
  4. <div class="flexslider">
  5. <ul class="slides">
  6. <li>
  7. <div class="w3l_banner_nav_right_banner">
  8. <h3>Make your <span>food</span> with Spicy.</h3>
  9. <div class="more">
  10. <a href="products.html" class="button--saqui button--round-l button--text-thick" data-text="Shop now">Shop now</a>
  11. </div>
  12. </div>
  13. </li>
  14. <li>
  15. <div class="w3l_banner_nav_right_banner1">
  16. <h3>Make your <span>food</span> with Spicy.</h3>
  17. <div class="more">
  18. <a href="products.html" class="button--saqui button--round-l button--text-thick" data-text="Shop now">Shop now</a>
  19. </div>
  20. </div>
  21. </li>
  22. <li>
  23. <div class="w3l_banner_nav_right_banner2">
  24. <h3>upto <i>50%</i> off.</h3>
  25. <div class="more">
  26. <a href="products.html" class="button--saqui button--round-l button--text-thick" data-text="Shop now">Shop now</a>
  27. </div>
  28. </div>
  29. </li>
  30. </ul>
  31. </div>
  32. </section>
  33. @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 :

  1. +--------+-----------+-------------------------------+-----------------+-----------------------------------------------------+--------------+
  2. | Domain | Method | URI | Name | Action | Middleware |
  3. +--------+-----------+-------------------------------+-----------------+-----------------------------------------------------+--------------+
  4. | | GET|HEAD | / | | App\Http\Controllers\HomeController@index | web |
  5. | | GET|HEAD | _dusk/login/{userId}/{guard?} | | Laravel\Dusk\Http\Controllers\UserController@login | web |
  6. | | GET|HEAD | _dusk/logout/{guard?} | | Laravel\Dusk\Http\Controllers\UserController@logout | web |
  7. | | GET|HEAD | _dusk/user/{guard?} | | Laravel\Dusk\Http\Controllers\UserController@user | web |
  8. | | GET|HEAD | api/user | | Closure | api,auth:api |
  9. | | GET|HEAD | product | product.index | App\Http\Controllers\ProductController@index | web |
  10. | | POST | product | product.store | App\Http\Controllers\ProductController@store | web |
  11. | | GET|HEAD | product/create | product.create | App\Http\Controllers\ProductController@create | web |
  12. | | GET|HEAD | product/{product} | product.show | App\Http\Controllers\ProductController@show | web |
  13. | | PUT|PATCH | product/{product} | product.update | App\Http\Controllers\ProductController@update | web |
  14. | | DELETE | product/{product} | product.destroy | App\Http\Controllers\ProductController@destroy | web |
  15. | | GET|HEAD | product/{product}/edit | product.edit | App\Http\Controllers\ProductController@edit | web |
  16. +--------+-----------+-------------------------------+-----------------+-----------------------------------------------------+--------------+

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:

  1. 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 vue
npm audit fix --force
npm 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 use keyword 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)]);
}