{{ $cards->appends(['content' => request()->content])->links() }}
标签: laravel
laravel5.7 passport
composer require laravel/passport php artisan migrate php artisan passport:install
app/User.php
<?php namespace App; use Laravel\Passport\HasApiTokens; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use HasApiTokens, Notifiable; }
app/Providers/AuthServiceProvider.php
<?php namespace App\Providers; use Laravel\Passport\Passport; use Illuminate\Support\Facades\Gate; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * * @var array */ protected $policies = [ 'App\Model' => 'App\Policies\ModelPolicy', ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->registerPolicies(); Passport::routes(); } }
config/auth.php
'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ],
laravel5.7 redis socket.io
composer require predis/predis
.env
BROADCAST_DRIVER=redis
config/app.php
取消注释providers下App\Providers\BroadcastServiceProvider::class,
创建文件app/Events/ChatRoom.php
<?php namespace App\Events; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class ChatRoom implements ShouldBroadcast { public $data; private $channels; /** * Create a new event instance. * * @return void */ public function __construct($channels, $data) { // $this->channels = $channels; $this->data = $data; } /** * Get the channels the event should be broadcast on. * * @return array */ public function broadcastOn() { return $this->channels; } }
调用
use Event, App\Events\ChatRoom;
Event::fire(new ChatRoom($channel, ‘data’));
开了CND 有页面注释掉代码都无效。
thinkphp,laravel,开了CND 有页面注释掉代码都无效。
CDN有缓存,页面不刷新
用动态CDN或临时解决方案缓存配置,文件夹,/index.php/Home,0秒刷新。
laravel $error view 里无效
\Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class,
将上面的两句在protected $middlewareGroups里移动到protected $middleware里
必须在protected $middlewareGroups里删掉
laravel5找回密码改中文
5.7
lang/zh_cn.json
{ "Login": "登陆", "E-Mail Address": "邮箱", "Password": "密码", "Remember Me": "记住我", "Forgot Your Password?": "忘记密码?", "Register": "注册", "Name": "姓名", "Confirm Password": "重复密码", "Reset Password": "重设密码", "Send Password Reset Link": "发送邮件", "Logout": "退出", "Reset Password Notification": "找回密码", "You are receiving this email because we received a password reset request for your account.": "您收到此电子邮件,因为我们收到了找回密码请求您的账户。", "If you did not request a password reset, no further action is required.": "如果没有请求找回密码,则不需要进一步的操作。", "Hello!": "您好!", "Regards": "真挚问候", "If you’re having trouble clicking the ": "如果您不能点击" }
5.4
php artisan vendor:publish --tag=laravel-notifications//找回密码邮件模版 php artisan make:notification ResetPassword//找回密码邮件通知
App/Notifications/Resetpassword.php
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; class ResetPassword extends Notification { use Queueable; /** * The password reset token. * * @var string */ public $token; /** * Create a notification instance. * * @param string $token * @return void */ public function __construct($token) { $this->token = $token; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['mail']; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return (new MailMessage) ->subject('找回密码') ->line('您收到此电子邮件,因为我们收到了找回密码请求您的账户。') ->action('重设密码', route('password.reset', $this->token)) ->line('如果没有请求找回密码,则不需要进一步的操作。'); } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ public function toArray($notifiable) { return [ // ]; } }
app\User.php
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use App\Notifications\ResetPassword as ResetPasswordNotification; class User extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; public function sendPasswordResetNotification($token) { $this->notify(new ResetPasswordNotification($token)); } }
views/vendor/notifications/email.blade.php
@component('mail::message') {{-- Greeting --}} @if (! empty($greeting)) # {{ $greeting }} @else @if ($level == 'error') # 错误! @else # 您好! @endif @endif {{-- Intro Lines --}} @foreach ($introLines as $line) {{ $line }} @endforeach {{-- Action Button --}} @if (isset($actionText)) <?php switch ($level) { case 'success': $color = 'green'; break; case 'error': $color = 'red'; break; default: $color = 'blue'; } ?> @component('mail::button', ['url' => $actionUrl, 'color' => $color]) {{ $actionText }} @endcomponent @endif {{-- Outro Lines --}} @foreach ($outroLines as $line) {{ $line }} @endforeach <!-- Salutation --> @if (! empty($salutation)) {{ $salutation }} @else 来自,<br>{{ config('app.name') }} @endif <!-- Subcopy --> @if (isset($actionText)) @component('mail::subcopy') 如果您不能点击"{{ $actionText }}"按钮,请复制下面的网址粘贴到您的浏览器: [{{ $actionUrl }}]({{ $actionUrl }}) @endcomponent @endif @endcomponent
laravel常用命令
//执行迁移 php artisan migrate //数据回滚 php artisan migrate:rollback //webpack生产 npm run production //发布webpack npm run dev //重建节点 npm rebuild node-sass //创建新表 php artisan make:migration create_表名_table --create=表名 //填充数据 php artisan db:seed //添加字段 php artisan make:migration add_添加信息_to_表名_table --table=表名 //创建控制器 php artisan make:controller 控制器复数Controller --resource //创建模块 php artisan make:model 模块 -m //创建视图 php artisan generate:view 文件夹.视图 //创建控制器模块数据库增删改查文件 php artisan generate:resource 表名 //查看路由 php artisan route //自动加载 composer dumpautoload //重置key php artisan key:generate
laravel 项目迁移
git clone https://github.com/
cp -f .env.example .env
vi .env
chmod -R 777 bootstrap/cache
chmod -R 777 storage
composer dumpautoload
composer update
php artisan key:generate
laravel error mysql 5.5.55
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t
oo long; max key length is 767 bytes (SQL: alter table `users` add unique `
users_email_unique`(`email`))
use Illuminate\Support\Facades\Schema; public function boot() { // Schema::defaultStringLength(191); }
laravel npm run dev error
错误:SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
node版本低,node5.0在文件第一行加 ”use strict”,或者更新node
brew upgrade node#更新node
curl -sL https://deb.nodesource.com/setup_6.x | bash –
apt-get install nodejs
错误:cross-env NODE_ENV=development webpack –watch –progress –hide-modules –config=node_modules/laravel-mix/setup/webpack.config.js
npm rebuild node-sass
npm run dev#successfully