laravel Production-ready

https://serversideup.net/open-source/spin/ Laravel sail https://laravel.com/docs/11.x/installation#choosing-your-sail-services shinsenter laravel https://github.com/shinsenter/php/pkgs/container/laravel

2024-08-28 · 1 min · 7 words · Me

php artisan config:cache

https://serversideup.net/open-source/docker-php/docs/laravel/laravel-automations#php-artisan-configcache This command caches all configuration files into a single file, which can then be quickly loaded by Laravel. Once the configuration is cache, the .env file will no longer be loaded.

2024-08-15 · 1 min · 32 words · Me

serversideup VPS-Benchmarks-for-Self-hosters

https://521dimensions.notion.site/VPS-Benchmarks-for-Self-hosters-c6eca7c5f16d4bb8aeb989174fc58ffe. Hetzner Cloud prohosting24 https://prohosting24.net/genoa 這間評價可,高防、效能不錯,無限流量,但用太多會限流,或是被踢掉,不能有法

2024-05-10 · 1 min · 6 words · Me

Livewire form and outside form with button action maybe different your think

In liveiwre word some button action and alpine @click action be clicked, livewire 3 update (ajax) is different your think. Component public $test_input=1; public function tt() { info('tt'); info($this->test_input); } blade <div class="row row-cols-1 row-cols-md-3 g-4" x-data> <form wire:submit="tt"> <input type="text" wire:model='test_input'> <button type="submit">form type=submit</button> {{-- // update (ajax) --}} <button type="button">form type=button</button> {{-- // No update (ajax) --}} <button wire:click='tt; $wire.test_input=3;'>form wire:click</button> {{-- // update (ajax) and run twice --}} <button @click='$wire.tt; $wire.test_input=3;'>form @click</button> {{-- // update (ajax) and run twice --}} </form> <button type="submit">out form type=submit</button> {{-- // No update (ajax) --}} <button type="button">out form type=button</button> {{-- // No update (ajax) --}} <button wire:click='tt; $wire.test_input=3;'>out form wire:click</button> {{-- // update (ajax) --}} <button @click='$wire.tt; $wire.test_input=3;'>out form @click</button> {{-- // update (ajax) --}} </div> So be careful and try to understand ...

2023-12-31 · 1 min · 147 words · Me

laravel Socialite line How to

Thanks https://medium.com/laravel-news/adding-auth-providers-to-laravel-socialite-ca0335929e42 This have problems https://socialiteproviders.com/Line/ composer require socialiteproviders/line create app/Providers/LineProvider.php https://github.com/SocialiteProviders/Line/blob/master/Provider.php namespace App\Providers; use GuzzleHttp\RequestOptions; use Laravel\Socialite\Two\InvalidStateException; use \SocialiteProviders\Manager\OAuth2\AbstractProvider; use \SocialiteProviders\Manager\OAuth2\User; class LineProvider extends AbstractProvider { public const IDENTIFIER = 'LINE'; /** * The separating character for the requested scopes. * * @var string */ protected $scopeSeparator = ' '; /** * The scopes being requested. * * @var array */ protected $scopes = [ 'openid', 'profile', 'email', ]; /** * Get the authentication URL for the provider. * * @param string $state * @return string */ protected function getAuthUrl($state) { return $this->buildAuthUrlFromBase( 'https://access.line.me/oauth2/v2.1/authorize', $state ); } /** * Get the token URL for the provider. * * @return string */ protected function getTokenUrl() { return 'https://api.line.me/oauth2/v2.1/token'; } /** * Get the raw user for the given access token. * * @param string $token * @return array */ protected function getUserByToken($token) { $response = $this->getHttpClient()->get( 'https://api.line.me/v2/profile', [ RequestOptions::HEADERS => [ 'Authorization' => 'Bearer '.$token, ], ] ); return json_decode((string) $response->getBody(), true); } /** * Map the raw user array to a Socialite User instance. * * @param array $user * @return \Laravel\Socialite\User */ protected function mapUserToObject(array $user) { return (new User())->setRaw($user)->map([ 'id' => $user['userId'] ?? $user['sub'] ?? null, 'nickname' => null, 'name' => $user['displayName'] ?? $user['name'] ?? null, 'avatar' => $user['pictureUrl'] ?? $user['picture'] ?? null, 'email' => $user['email'] ?? null, ]); } // /** // * Get the POST fields for the token request. // * // * @param string $code // * // * @return array // */ // protected function getTokenFields($code) // { // return array_merge(parent::getTokenFields($code), [ // 'grant_type' => 'authorization_code', // ]); // } /** * @return \SocialiteProviders\Manager\OAuth2\User */ public function user() { if ($this->hasInvalidState()) { throw new InvalidStateException(); } $response = $this->getAccessTokenResponse($this->getCode()); if ($jwt = $response['id_token'] ?? null) { $bodyb64 = explode('.', $jwt)[1]; $user = $this->mapUserToObject(json_decode(base64_decode(strtr($bodyb64, '-_', '+/')), true)); } else { $user = $this->mapUserToObject($this->getUserByToken( $token = $this->parseAccessToken($response) )); } $this->credentialsResponseBody = $response; if ($user instanceof User) { $user->setAccessTokenResponseBody($this->credentialsResponseBody); } return $user->setToken($this->parseAccessToken($response)) ->setRefreshToken($this->parseRefreshToken($response)) ->setExpiresIn($this->parseExpiresIn($response)); } } edit app/Providers/AppServiceProvider.php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Register any application services. */ public function register(): void { // } /** * Bootstrap any application services. */ public function boot(): void { $this->bootLineSocialite(); } public function bootLineSocialite(): void { // // laravel Socialite 和 Socialite Line 有問題,就是 在初始載入不了 // // 看Socialite Line 作者還有在3星期前維謢,所以就不知道怎麼回事 // // https://medium.com/laravel-news/adding-auth-providers-to-laravel-socialite-ca0335929e42 $socialite = $this->app->make('Laravel\Socialite\Contracts\Factory'); $socialite->extend( 'line', function ($app) use ($socialite) { $config = config('services.line'); // https://github.com/SocialiteProviders/Line/blob/master/Provider.php return $socialite->buildProvider(LineProvider::class, $config); // \SocialiteProviders\Line\Provider::class } ); } } routes/web.php Route::get('/auth/redirect', function () { return Socialite::driver('line')->redirect(); }); Route::get('/auth/callback', function () { $user = Socialite::driver('line')->user(); dd($user); });

2023-09-02 · 3 min · 433 words · Me

Laravel Livewire with WinNMP Part II

https://github.com/sueboy19/livewire_demo

2023-06-04 · 1 min · word · Me

Laravel Livewire with WinNMP

winnmp for windows a. create project livewire (Database and user auto create livewire) b. https://winnmp.wtriple.com/tutorial/laravel update composer a. mkdir new directory "t" b. cd t c. https://getcomposer.org/download/ c1. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" c2. php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" c3. php composer-setup.php c4. php -r "unlink('composer-setup.php');" c5. mv composer.phar to C:\WinNMP\bin\composer cd \WinNMP\WWW\livewire a. delete index.php b. composer create-project --prefer-dist laravel/laravel . c. composer require laravel/ui d. composer install e. edit .env e1. DB_DATABASE=livewire DB_USERNAME=livewire f. php artisan ui bootstrap --auth g. php artisan migrate h. developer tools composer require doctrine/dbal composer require --dev barryvdh/laravel-ide-helper composer require --dev beyondcode/laravel-dump-server composer require --dev barryvdh/laravel-debugbar composer require --dev roave/security-advisories:dev-master php artisan vendor:publish --provider="BeyondCode\DumpServer\DumpServerServiceProvider" php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider" I. php artisan key:generate install node.js for windows a. https://nodejs.org/zh-tw/download b. npm install c. npm run dev ...

2023-06-03 · 2 min · 249 words · Me

laravel schedule cron docker dockerfile docker-compose

cron php laravel UI Boostrap jetstream docker-compose laravel_docker dokcer-compose.yml cron: build: ./infra/docker/cron env_file: ./env.mariadb.local.env stop_signal: SIGTERM depends_on: - app volumes: - ./backend:/work/backend Dockerfile FROM php:8.0.11-fpm-buster LABEL maintainer="ucan-lab <yes@u-can.pro>" #SHELL ["/bin/bash", "-oeux", "pipefail", "-c"] # timezone environment ENV TZ=Asia/Taipei \ # locale LANG=en_US.UTF-8 \ LANGUAGE=en_US:UTF-8 \ LC_ALL=en_US.UTF-8 \ # Laravel environment APP_SERVICES_CACHE=/tmp/cache/services.php \ APP_PACKAGES_CACHE=/tmp/cache/packages.php \ APP_CONFIG_CACHE=/tmp/cache/config.php \ APP_ROUTES_CACHE=/tmp/cache/routes.php \ APP_EVENTS_CACHE=/tmp/cache/events.php \ VIEW_COMPILED_PATH=/tmp/cache/views \ # SESSION_DRIVER=cookie \ LOG_CHANNEL=stderr \ DB_CONNECTION=mysql \ DB_PORT=3306 RUN apt-get update RUN apt-get -y install locales libicu-dev libzip-dev htop cron nano RUN apt-get -y install default-mysql-client RUN locale-gen en_US.UTF-8 && localedef -f UTF-8 -i en_US en_US.UTF-8 RUN docker-php-ext-install intl pdo_mysql zip bcmath exif RUN apt-get clean && rm -rf /var/lib/apt/lists/* # 自訂 RUN mkdir -p /tmp/cache WORKDIR /work/backend # 這行超級重要 把初始環境的變數寫死 RUN printenv > /etc/environment # 把log 輸出到 docker 上 RUN ln -sf /proc/1/fd/1 /var/log/laravel-scheduler.log #ADD crontab /var/spool/cron/crontabs/root #RUN chown root:crontab /var/spool/cron/crontabs/root #RUN chmod 0600 /var/spool/cron/crontabs/root #RUN crontab -l | { cat; echo "* * * * * . /usr/local/bin/php /work/backend/artisan config:cache && php artisan schedule:run >> /var/log/cron.log 2>&1"; } | crontab - #RUN crontab -l | { cat; echo "* * * * * date >> /var/log/cron.log"; } | crontab - #RUN crontab -l | { cat; echo "* * * * * echo hello > /proc/1/fd/1 2>/proc/1/fd/2"; } | crontab - COPY crontab /etc/cron.d/crontab RUN chmod 0644 /etc/cron.d/crontab RUN crontab /etc/cron.d/crontab CMD bash -c "/usr/local/bin/php /work/backend/artisan config:cache && cron -f" cron ...

2022-02-07 · 2 min · 361 words · Me

Expected response code 250 but got an empty response laravel 8

https://blog.trippyboy.com/2021/laravel/laravel-expected-response-code-250-but-got-an-empty-response/ ./config/mail.php 'local_domain' => env('MAIL_HOST'), 'default' => env('MAIL_MAILER', 'smtp'), 'mailers' => [ 'smtp' => [ 'transport' => 'smtp', 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'port' => env('MAIL_PORT', 587), 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'timeout' => null, 'auth_mode' => null, 'local_domain' => env('MAIL_HOST'), ],

2021-09-14 · 1 min · 46 words · Me

laravel rules validate multiple row for other column

Multiple parts (id, name, finish, finish_noe) finish = 2 is Job OK protected $rules = [ 'parts.*.finish_note' => ['required_if:parts.*.finish,2'], ]

2021-09-14 · 1 min · 20 words · Me

Laravel dotenv Kernel multile

Http/Kernel.php .env .env-local.env .env-staging.env .env-production.env class Kernel extends HttpKernel { public function __construct(Application $app, Router $router) { parent::__construct($app, $router); $environmentPath = __DIR__.'/../../'; $dotenv = Dotenv::createUnsafeImmutable($environmentPath, '.env'); // getenv not thread safe $dotenv->safeLoad(); //this is important $dotenv = Dotenv::createUnsafeImmutable($environmentPath, '.env.'.getenv('APP_ENV').'.env'); // getenv not thread safe $dotenv->safeLoad(); //this is important } .env``` APP_ENV=local LOG_CHANNEL=stack BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" .env.local.env``` APP_NAME=OOXX_Local APP_KEY=base64:NDvP.........g= APP_DEBUG=true APP_URL=http://localhost QUERY_DETECTOR_ENABLED=true DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_NOTIFY=true MAIL_MAILER=smtp MAIL_HOST=smtp.ooxx.org MAIL_PORT=587 MAIL_USERNAME=ooxx@ooxx.com MAIL_PASSWORD= MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=ooxx01@ooxx.com MAIL_FROM_NAME="${APP_NAME}" AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION= AWS_BUCKET= AWS_BUCKETTEST= .env.local.env``` ...

2021-04-16 · 1 min · 121 words · Me

laravel ->paginate need becareful

When you use some model ->paginate Get Illuminate\Pagination\LengthAwarePaginator But Value Don’t Back To Variable. $orders->paginate(10) $orders = $orders->paginate(10) So $this->orders->paginate(10) $this->oorders = $this->oorders->paginate(10)

2021-03-31 · 1 min · 23 words · Me

livewire public variable eloquent for security column

Get livewire public variable Front web Try to get public $order``` document.addEventListener(’livewire:load’, function () { console.log(@this.order); livewire window.livewire.find eloquent collection https://github.com/livewire/livewire/issues/1641?fbclid=IwAR0uHylkj-1vg8p5jUoBgPYfuAYsWnBhgp6EK2bJcBce8ze-tdtAa8ElLNY#issuecomment-736146468 Eloquent Collection data won't be made available to the front end unless you have the collection properties specified in the $rules array as the contents are models, so the same conditions apply to it as apply to just a single model property. This is for security reasons so the whole collection and all properties aren't just sent to the front end. See the example here of binding to an eloquent collection https://laravel-livewire.com/docs/2.x/properties...... But a standard collection (not eloquent) will work but only with primitive data types. If any models are added to the collection or any php objects (not eloquent models), they will be serialised into an array. So eloquent use for public variable is OK. \====== Other way use makeHidden()

2021-03-30 · 1 min · 142 words · Me

[轉] 18 Tips to Optimize Your Laravel Database Queries | Laravel News (laravel-news.com)

 18 Tips to Optimize Your Laravel Database Queries | Laravel News (laravel-news.com)

2021-03-26 · 1 min · 12 words · Me

livewire locale lang

middleware routes/web.php``` Route::group([‘prefix’ => ‘member’, ‘as’ => ‘member.’, ‘middleware’ => [‘auth’, ‘setLocale:zh-tw’]], function () { Route::get(’/’, App\Http\Livewire\MemberList::class); }); app/Http/Middleware/SetLocale.php.php``` namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; class SetLocale { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, string $lang) { app()->setLocale($lang); return $next($request); } }

2021-02-24 · 1 min · 60 words · Me

Search two time then change paginate table record have problem

https://github.com/livewire/livewire/issues/1908

2020-10-29 · 1 min · word · Me

laravel controller use class but no pass class ?

https://www.youtube.com/watch?v=ShrS3HXwzPg``` class PostController extends Controller { public function update(Post $post, before class PostController extends Controller { public function update($post_id, $post = Post::findOrFail($post_id); And many more things.

2020-10-24 · 1 min · 26 words · Me

file_put_contents failed to open stream: Permission denied /tmp/cache/views/

php artisan view:clear ```https://laracasts.com/discuss/channels/laravel/permission-denied-on-storageframeworkviews https://laravel.io/forum/07-06-2016-session-permissions-issue https://laracasts.com/discuss/channels/general-discussion/laravel-framework-file-permission-security

2020-10-22 · 1 min · 6 words · Me

laravel livewire file update Real-Time File Validation mutile files

 https://laravel-news.com/livewire-file-upload Real-Time File Validation``` use Livewire\Component; use Livewire\WithFileUploads; class Show extends Component { use WithFileUploads; public $files = []; public function updatedFiles() // 即時檢查檔案格式 { $this->validate([ 'files.*' => 'image|max:1024', // 1MB Max ]); } public function store() { $filenames = collect($this->photos)->map->store('photos'); 'files' => $filenames->implode(','), updatedFiles() is Hook into the “updated” updatedPhoto public $Photo updatedPhotos public $photos = [] updatedFile public $file updatedFiles public $files = []

2020-10-21 · 1 min · 66 words · Me

laravel livewire Name problem

Use - and lowwercase App/Http/Livewire/Order/DropdownMaterial.php``` class DropdownMaterial extends Component { resources/views/livewire/order/create.blade.php``` @livewire('order.dropdown-material', ['post' => $order_material_id])

2020-10-20 · 1 min · 15 words · Me