Category : mysql

I create new command in laravel: public function handle() { $serversList = [ ‘cubegame.pl’, ‘feerko.pl’, ‘skyup.pl’, ‘mcosada.pl’, ‘dragon-craft.pl’, ‘gc2.pl’, ‘mc.craftplay.pl’, ‘iskyblock.pl:25600’, ‘mc.craftmc.pl’, ‘mc.realcraft.pl’, ‘katomc.pl’, ‘mc.minestar.pl’, ]; foreach ($serversList as $server) { $req = Http::get("https://api.mcsrvstat.us/2/$server"); if ($req->ok()) { $status = $req->json(); // dump($status[‘motd’][‘html’][0]); $serv = Server::updateOrCreate( [ ‘name’ => $server, ‘ip’ => $status[‘ip’] ], [ ‘motd’ ..

Read more

How I can associate business with employees and owner (User table but using roles like Admin/Owner/Manager/Employee) and branches? public function getIsAdminAttribute() { return $this->hasRole(‘administrator’); } public function getIsOwnerAttribute() { return $this->hasRole(‘owner’); } public function getIsManagerAttribute() { return $this->hasRole(‘manager’); } public function getIsEmployeeAttribute() { return $this->hasRole(’employee’); } So I can know who is owner of business ..

Read more

I am new to laravel and building my first project using it. I want to query two tables (Cases and Detail) using orWhere() function. Please tell me the changes I need to make in my existing code. Controller.php $key = trim($request->get(‘q’)); $cases = Cases::query() ->where(‘cnic’, "$key") ->orWhere(‘eventDate’, "$key") ->get(); return view(‘adminHome’,[‘user’ => $cases ]); The ..

Read more

I am having those two table Schemas (Client and Product Models) with a One to Many relationship. I am using mysql database. Schema::create(‘clients’, function (Blueprint $table) { $table->id(); $table->string(‘name’); $table->string(‘job’); $table->timestamps(); }); Schema::create(‘products’, function (Blueprint $table) { $table->id(); $table->foreignId(‘client_id’)->constrained(); $table->string(‘productName’)->unique(); $table->integer(‘quantity’); $table->float(‘unitPrice’); $table->timestamps(); }); I also tried to use the syntax below instead of $table->foreignId(‘client_id’)->constrained(); ..

Read more

Migrations fails when I try to execute php artisan migrate and php artisan migrate:refresh Code Users Table (Migrated successfully) public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->integer(‘id’,)->primary(); $table->string(‘name’, 255); $table->string(‘surname’, 255); $table->string(’email’, 255)->unique(); $table->string(‘password’, 255); $table->string(‘profile_image’, 255); $table->string(‘profile_cover’, 255); $table->rememberToken(); $table->char(‘token’, 255)->unique()->nullable()->default(null); $table->enum(‘role’, [‘user’, ‘driver’, ‘,merchant’, ‘storemanager’, ‘storeoperator’, ‘company’, ’employee’]); $table->dateTime(‘created’); $table->dateTime(‘updated’); }); ..

Read more

I have a users table Schema::create(‘users’, function (Blueprint $table) { $table->id(); $table->string(‘name’); $table->string(’email’)->unique(); $table->timestamp(’email_verified_at’)->nullable(); $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); and a roles table Schema::create(‘roles’, function (Blueprint $table) { $table->id(‘role_id’); $table->string(‘role_name’); }); now i want to create a user_role table which have two foreign keys Schema::create(‘user_role’, function (Blueprint $table) { $table->foreign(‘user_id’)->references(‘id’)->on(‘users’); $table->foreign(‘role_id’)->references(‘role_id’)->on(‘roles’); }); but i’m getting an ..

Read more

I’m Running the following query without any problem in Mysql Database but it throws error on server which database is MariaDB $projects = V2Project::leftJoin(‘v2_project_locations as v2pl’, ‘v2pl.project_id’, ‘v2_projects.id’) ->leftJoin(‘v2_locations as v2l’, ‘v2l.id’, ‘v2pl.location_id’) ->selectRaw(‘v2_projects.id, v2_projects.name, group_concat(v2l.name) as locations’) ->withDepartmentInMind() ->onlyAuthorizedObjects(); if($by_current_step == true) { $projects = $projects->where(‘current_step’, ‘plan’); } if($search_val) { $projects = $projects->whereIn(‘v2_projects.id’, $search_val); ..

Read more

$products = product::select([ DB::raw(‘product_no as number’), DB::raw(‘product_name as name’), DB::raw(‘sum(total) as total’), DB::raw(‘sum(product_qty) as qty’), DB::raw(‘sum(product_price) as price’), ]) ->groupBy(‘number’) ->groupBy(‘name’) ->get(); return view (‘view’,[‘products’=>$products]); i need to insert the result to another table in database by laravel Sourc..

Read more

We’re starting a Laravel API from scratch where each user has his own MYSQL server (Amazon RDS instance). The user’s databases list will be less than 100 users, so less than 100 databases instances. We’re discussing with my partner because he’s storing each server settings in the .env file (APPROACH_1), he has a script that ..

Read more

I m using Laravel : 8.^0. After a few migrations i m trying to run php artisan schema:dump to generate an sql file. But i m getting the below error mysqldump: unknown variable ‘column-statistics=0’ mysqldump: unknown variable ‘set-gtid-purged=OFF’ SymfonyComponentProcessExceptionProcessFailedException The command "mysqldump –user="${:LARAVEL_LOAD_USER}" –password="${:LARAVEL_LOAD_PASSWORD}" –host="${:LARAVEL_LOAD_HOST}" –port="${:LARAVEL_LOAD_PORT}" –skip-add-locks –skip-comments –skip-set-charset –tz-utc –set-gtid-purged=OFF "${:LARAVEL_LOAD_DATABASE}" –routines –result-file="${:LARAVEL_LOAD_PATH}" –no-data" ..

Read more

Let’s assume that I have 2 tables: Users: Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’); $table->string(‘name’); $table->string(’email’)->unique(); $table->integer(‘age’) $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); Phones: Schema::create(‘phones’, function (Blueprint $table) { $table->increments(‘id’); $table->integer(‘user_id’)->unsigned(); $table->string(‘phone’); $table->timestamps(); $table->foreign(‘user_id’)->references(‘id’)->on(‘users’) ->onDelete(‘cascade’); }); User Model: public function phone() { return $this->hasOne(‘AppPhone’); } Phone Model: public function user() { return $this->belongsTo(‘AppUser’); } When I perform ..

Read more

Currently in a Laravel project using AWS EB with RDS. When I run php artisan migrate –seed then I get PHP Notice: Undefined index: RDS_HOSTNAME in /var/app/current/config/database.php on line 5 PHP Notice: Undefined index: RDS_USERNAME in /var/app/current/config/database.php on line 6 PHP Notice: Undefined index: RDS_PASSWORD in /var/app/current/config/database.php on line 7 PHP Notice: Undefined index: RDS_DB_NAME ..

Read more

I have two models using different tables on two different connections, User and UserInfo. User has a UserInfo hasMany relation: public function userInfo() { return $this->hasMany(‘pathtoUserInfo’,’User_ID’); } and UserInfo has a User belongsTo relation: public function user() { return $this->belongsTo(‘anotherpathtoUser’, ‘User_ID’, ‘User_ID’); } I would like to find the first user with more than one ..

Read more