EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/

laravel eloquent orm

 [one to one]


Table: User, Phone

Model: User

Relation: return $this->hasOne('App\Phone');


Talbe Phone need have user_id. Auto use User id -> Phone user_id




Table: User, Phone

Model: Phone

Relaion: return $this->belongsTo('App\User');


Table Phone need have user_id. Auto use User id -> User user_id




[one to many]


Table: Post, Comment

Model: Post

Relation: return $this->hasMany('App\Comment');


Table Comment need have post_id. Auto use Post id -> Comment post_id




Table: Post, Comment

Model: Comment

Relaion: return $this->belongsTo('App\Post');


Table Comment need have post_id. Auto Post id -> Comment post_id




[Many To Many]


Table: User, Role, Role_User

 Table Role_User must have user_id, role_id

Model: User


way1:

Relaion: return $this->belongsToMany('App\Role', 'role_user');


way2:

Relaion: return $this->belongsToMany('App\Role');

Must database/migrations defined talbe class like "CreateRoleUserPivotTable"













livewire laravel route problem!

larvel 8 remove Providers/RouteServiceProvider.php namespace. Maybe you add back again.



        protected $namespace = 'App\Http\Controllers';
...

        $this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));
        });

Add backup namespace then get problem for livewire. Every route just use App\Http|controllers ooxxooxxooxx.

OLD Way


web.php

Route::resource('users', 'UsersController');
Route::delete('users/destroy', 'UsersController@massDestroy');

Get Error
Route::resource('orders', 'livewire.order');
Route::resource('orders', 'livewire@order');
Route::view('orders', [\App\Http\Livewire\Order::class, 'render']);

Maybe Way


web.php

Route::view('orders', 'livewire.order');

Files:
\app\Http\Livewire\Order.php inside use return view('livewire.order');
\resources\views\livewire\order.blade.php 

Get Error
Undefined variable: orders  or other ooxxooxx 
Alwasy get this Error. 

web.php

Route::get('/admin/orders', [\App\Http\Livewire\Order::class, 'render']);

Files:
\app\Http\Livewire\Order.php  
And use
return <<<'blade'
blade;

Get plain text @foreach($orders as o$key -> $permission 
Same Error.
Beacuse view run first. Only create view then @livewire('')

example:
order and orderlist

order view for fist(main) load page. orderlist be loaded by order view. order view have @livewire('orderlist').

https://stackoverflow.com/questions/64038485/laravel-livewire-components-or-controllers

or just remove namespace


Route::get('/admin/orders', \App\Http\Livewire\Order::class);

Don't add namespace in app/Http/livewire/ any file. Always get errors.

php auth role is_admin isAdmin or .... check role admin

User model getIsAdminAttribute()

https://www.youtube.com/watch?v=j97iBwTPlNE

https://stackoverflow.com/questions/58889575/laravel-5-8-authuser-is-not-using-user-model



public function getIsAdminAttribute()
{
   return (bool) $this->admin;
}

Auth::user()->isAdmin or auth()->user()->isAdmin

https://laracasts.com/discuss/channels/code-review/how-to-check-user-role-after-login


namespace App;

use App\Role;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    public function getIsAdminAttribute()
    {
        return $this->roles->pluck( 'name' )->contains( 'admin' );
    }

    public function roles()
    {
        // you will need a role model
        // Role::class is equivalent to string 'App\Role'
        return $this->belongsToMany( Role::class, 'users_role' );
    }
}
LoginController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use Input;
use Validator;
use Redirect;

class LoginController extends Controller
{
    //
    
    public function login_post( Request $request )
    {
        $data = Input::except( array( '_token' ) );

        // var_dump($data);

        $rule = array(
            'email'    => 'required|email',
            'password' => 'required',
        );

        $validator = Validator::make( $data, $rule );

        if ($validator->fails()) {
            // should do something
        } else {
            // no need to populate $data again with the same values
            // $data = Input::except( array( '_token' ) );
            
            if (Auth::attempt( $data )) {
                // here i want to check logged in user role
                $user = Auth::user();
                
                if ($user->roles->pluck( 'name' )->contains( 'admin' )) {
                    return Redirect::to( '/admin-dashboard' );
                }
                
                return Redirect::to( '/dashboard' );
            }
        }
    }
}

https://laravel.tw/docs/5.2/eloquent-serialization#appending-values-to-json

https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/111359/

方法簽名為getXXXAttribute
get XXX Attribute So XXX => IsAdmin

    public function getIsAdminAttribute()
    {
        return $this->roles()->where('id', 1)->exists();
    }

https://stackoverflow.com/questions/44017571/pass-current-eloquent-into-getxattribute-in-model


public function getIsAdminAttribute()
{   
   return Admin::where('user_id', $this->id)->count() > 0;
}

Error Running: npm install vue-template-compiler --save-dev --production=false

 Error 


  Additional dependencies must be installed. This will only take a moment.
  
  Running: npm install vue-template-compiler --save-dev --production=false
  


https://qiita.com/ucan-lab/items/f5bcdfceecffb9def4c5


Use yarn, Not npm


yarn add vue-template-compiler --dev --production=false
yarn run dev

[轉] Laravel Livewire vs Vue vs jQuery: Simple Example

 https://www.youtube.com/watch?v=o0HoP7WzRf0

php laravel UI Boostrap jetstream docker-compose

目錄裡面對應的檔案要先修改

=== 設定修改

[docker-compose]
 docker-compose.yml ./backend 在執行docker-compose目錄下建立backend目錄,或者是移動位置
db-store 使用的是 volumes


[mysql]
 infra/docker/mysql/Dockerfile
mysql user password root 等等自行變更,變更後要記得修改 infra/docker/php/Dockerfile

 infra/docker/mysql/my.cnf
collation_server = utf8mb4_unicode_ci


[php]
 infra/docker/php/Dockerfile 如果上面mysql設定有變更,記得這裡也要跟著變更
ENV TZ=Asia/Taipei
LANGUAGE=en_US:UTF-8


 infra/docker/php/php.ini
mbstring.language = zh-tw

[nginx]
 infra/docker/nginx/Dockerfile
ENV TZ=UTC+8



=== 指令開始執行

docker-compose up -d
  
docker-compose exec app composer create-project --prefer-dist laravel/laravel .

== jetstream Livewire !Now No Use


docker-compose exec app composer require laravel/jetstream
docker-compose exec app php artisan jetstream:install livewire  --teams
docker-compose exec app php artisan migrate

docker-compose exec web yarn install
docker-compose exec web yarn dev

== jetstream end

== Laravel UI Bootstrap Auth *more easy


docker-compose exec app composer require laravel/ui
docker-compose exec app php artisan ui bootstrap --auth
[ docker-compose exec app php artisan migrate ]

docker-compose exec web yarn install
docker-compose exec web yarn run dev

[ docker-compose exec web yarn add vue-template-compiler --dev --production=false ]

== Laravel UI Bootstrap end


docker-compose exec app composer require doctrine/dbal
docker-compose exec app composer require --dev barryvdh/laravel-ide-helper
docker-compose exec app composer require --dev beyondcode/laravel-dump-server
docker-compose exec app composer require --dev barryvdh/laravel-debugbar
docker-compose exec app composer require --dev roave/security-advisories:dev-master
docker-compose exec app php artisan vendor:publish --provider="BeyondCode\DumpServer\DumpServerServiceProvider"
docker-compose exec app php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"

=== remove all


docker-compose down --rmi all --volumes
docker-compose down --volumes

.參考:

https://github.com/ucan-lab/docker-laravel
https://github.com/ucan-lab/docker-laravel/blob/master/Makefile
https://qiita.com/ucan-lab/items/7824d1293fef4698c212

blade @can @cannot

https://laravel.com/docs/8.x/authorization#via-blade-templates


https://laravel.com/docs/8.x/authorization


The gate methods for authorizing abilities (allows, denies, check, any, none, authorize, can, cannot) and the authorization Blade directives (@can, @cannot, @canany) can receive an array as the second argument. These array elements are passed as parameters to gate, and can be used for additional context when making authorization decisions