When juse livewire at blade.php
Must have Div At first. <div style="text-align: center"> <button wire:click="increment">+</button> <h1>{{ $count }}</h1> </div> +{{ $count }}
App/Http/Livewire/Orders.php```
namespace App\Http\Livewire;
use Gate;
use Livewire\Component;
use Symfony\Component\HttpFoundation\Response;
class Orders extends Component
{
public function render()
{
abort_if(Gate::denies(‘order_access’), Response::HTTP_FORBIDDEN, ‘403 Forbidden’);
return view('livewire.order'); } }
resources/views/livewire/order.blade.php
@extends(‘layouts.app’)
@section(‘content’)
@livewire(‘order.show’)
@endsection
App/Http/Livewire/Order/Show.php namespace App\Http\Livewire\Order;
public function render() { abort_if(Gate::denies('order_access'), Response::HTTP_FORBIDDEN, '403 Forbidden'); $this->orders = Order::all(); // Order::where('owner_id', auth()->id())->get(); // 只能看自己 return view('livewire.order.show'); } resources/views/livewire/order/show.blade.php
{{ virables }}
[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
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.
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.
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
https://www.youtube.com/watch?v=o0HoP7WzRf0