Category : postgresql

DB::statement(" CREATE VIEW course_market_view AS ( SELECT users.id, users.name, course.id, course.courseUniqueName, skills.id, skills.skill, subjects.id, subjects.subject FROM users LEFT JOIN course ON course.userId=users.id LEFT JOIN skills ON skills.userId=users.id LEFT JOIN subjects ON subjects.userId = users.id ) "); I’ve written the above code in the up method of my migration but when running migrate command, it shows ..

Read more

{"MPA0000004":{"2020-21":{"Q1":"100","Q2":"25","Q3":"","Q4":""},"2021-22":{"Q1":"5","Q2":"","Q3":"","Q4":""}},"MPA0000006":{"2020-21":{"Q1":"","Q2":"2","Q3":"","Q4":"4"},"2021-22":{"Q1":"","Q2":"6","Q3":"","Q4":"8"}},"MPA0000007":{"2020-21":{"Q1":"","Q2":"","Q3":"3","Q4":""},"2021-22":{"Q1":"","Q2":"","Q3":"7","Q4":""}}} Need data like this : ITEM_ID | YEAR | Q1 | Q2 |Q3 | Q4 Sourc..

Read more

I have a table Audit in a database that track the edit, delete and add operation in the application now I like to create a page OperationFeeds i wrote the query SELECT audits.old_values, audits.new_values, users."name" FROM audits INNER JOIN users ON audits.user_id = users."id" it work what i want in above query with following output ..

Read more

I want to hide the columns password & OTP ,that is included in $uses result. Actually these 2 columns are part of the users table. I’ve tried like below. But it generates the error – Method IlluminateSupportCollection::makeHidden does not exist . How to solve this? Any suggestions.. $users = DB::table(‘users’) ->join(‘location’, ‘users.id’, ‘=’, ‘location.id’) ->join(‘user_technical_details’, ..

Read more

Am trying to insert data to 2 tables. The first insertion – Orders::Create($requestData); works well. But the 2nd insertion –FileLogs::create($order); is not working. dd($order) shows data correctly, still it’s not get inserted to the db. It’s showing the error message Internal Server Error . any help to resolve this is much appreciated. public function store(Request ..

Read more

I’m getting error msg internal server error for below code. I guess that the 2 observers classes binded in eventServiceProvider is causing the error. I don’t know how to resolve this error. Pls help me with ur suggestions. Controller public function store(Request $request) { try{ $requestData=$request->all(); $validator = Validator::make($requestData, [ ‘fileId’ => ‘required|array’ ]); $response ..

Read more

class OrderFiles extends Migration { public function up() { Schema::create(‘order_files’, function (Blueprint $table) { $table->id(); $table->integer(‘orderId’)->unsigned(); $table->foreign(‘orderId’)->references(‘id’)->on(‘orders’); $table->integer(‘fileId’)->unsigned(); $table->foreign(‘fileId’)->references(‘id’)->on(‘files’); $table->string(‘status’); $table->softDeletes(); $table->timestamps(); }); } } I’ve this migration file, still I’m getting below error when running migration. I don’t have any idea about this error. Am using pgsql-13 & laravel-8. Any helps to resolve this ..

Read more

<?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateOrderFilesTable extends Migration { public function up() { Schema::create(‘order_files’, function (Blueprint $table) { $table->id(); $table->integer(‘orderId’)->unsigned(); $table->foreign(‘orderId’)->references(‘id’)->on(‘orders’); $table->integer(‘fileId’)->unsigned(); $table->foreign(‘fileId’)->references(‘id’)->on(‘files’); $table->string(‘status’); $table->softDeletes(); $table->timestamps(); }); } } For the above table, I have created a log table named files_change_logs as below ,in which the id column of the above order_files ..

Read more

Schema::create(‘order_files’, function (Blueprint $table) { $table->id(); $table->integer(‘orderId’)->unsigned(); $table->foreign(‘orderId’)->references(‘id’)->on(‘orders’); $table->integer(‘fileId’)->unsigned(); $table->foreign(‘fileId’)->references(‘id’)->on(‘files’); $table->string(‘status’); $table->softDeletes(); $table->timestamps(); }); I have created migration like above. In this, I want to change the datatype of column fileId to bigint . For that, I have created a migration like below. class ChangeFileIdInteger extends Migration { public function up() { Schema::table(‘order_files’, function (Blueprint ..

Read more

Schema::create(‘order_files’, function (Blueprint $table) { $table->integer(‘fileId’)->unsigned(); $table->foreign(‘fileId’)->references(‘id’)->on(‘filesizes’); }); I want to change the above foreign key column to $table->foreign(‘fileId’)->references(‘id’)->on(‘files’); . I have tried php artisan migrate:fresh & php artisan make:migration add_fileId_to_order_files_table –table=order_files – this shows the fileId column already exists. Any suggestions… Sourc..

Read more

The below given Laravel update operation returns true for dd($data). Bu t i want it to return the updated data. How to change this to get such an output. There is one condition i have that, the update should be called directly on the model .Any suggestions… $data=FileLogs::find($id)->update([‘orderId’=>$request->orderId,’fileId’=>$request->fileId,’status’=>$request->status]); //dd($data); Sourc..

Read more

I have a little bit of a chicken and egg problem here. I am building a multitenant app in Laravel where each tenant has their own database on a Postgrsql server. So I have a job to create a new tenant that calls: Schema::connection($this->tenant->getDatabaseConnection())->createDatabase($this->tenant->getDatabaseName()) So $this->tenant->getDatabaseConnection() chooses a tenant DB server to add the tenant ..

Read more

Controller public function update(Request $request,$id){ $validator = Validator::make( $request->all(), [ ‘orderId’ => ‘required|integer’, ‘fileId’ => ‘required|integer’, ‘status’ => ‘required|string’ ] ); if ($validator->fails()) { return response()->json($validator->errors(), 400); } $data=FileLogs::find($id)->update([‘$data->orderId’=>’$request->orderId’,’$data->fileId’=>’$request->fileId’,’$data->status’=>’$request->status’]); return response()->json([‘status’=>’success’,’StatusCode’=> 200,’message’=>’Successfully Updated’,’data’=>$data]); } The code is not working for update operation,but it is working in the below method. However , i want to do ..

Read more

I’m trying to do a conditional where query based on supplied parameter, however it returns no result whereas when I put the entire query directly to query builder it does return a result because there is that specific data in the table. Here’s what I currently have $tasks = DB::table(‘customer_master’) ->select(DB::raw("customer_name, substring(birthday,1,4)||’ – ‘||substring(birthday,5,2)||’ – ..

Read more

It seems like either I or Laravel 8.x has issues with its Aggregate Functions withAVG and withCount, when running PostgreSQL, but not MySQL. Trying to run following Elequent query: $product = Product::where(‘slug’, $slug) ->with(‘category’) ->withAvg(‘reviews’, ‘rating_general’) ->withAvg(‘reviews’, ‘rating_strength’) ->withAvg(‘reviews’, ‘rating_taste’) ->withAvg(‘reviews’, ‘rating_draw’) ->withCount(‘reviews’) ->firstOrFail(); Works on MySQL, but fails on PostgreSQL with the following error: ..

Read more

The below code shows Update Failed & not getting saved to the db. All the other functions in controller works fine. May i get ur helps to find where i went wrong. class PaymentStatusController extends Controller { public function update(Request $request,$id){ $validator = Validator::make( $request->all(), [ ‘StatusName’ => ‘string’, ‘ColorCode’ => ‘string’ ] ); if ..

Read more