Category : sql

I have the table like this billNumber unit slave 0001 1 6 0001 1 8 0001 1 7 Am expect to have the following result billnumber unit slave 0001 1 (3)=6,8,7 this is my query i have $issuedevice=Issue_to_sale::with(‘deviceNumb’,’user’) ->groupBy(‘unit’) ->get(); return json_encode(array(‘data’=>$issuedevice)); Help How can apply on my query above Sourc..

Read more

I am creating simple query in laravel which gives error i want sum of sub_total column with product_slug parameter from table $items=DB::table(‘carts’) ->join(‘products’,’products.product_id’,’=’,’carts.product_id’) ->select(‘carts.user_id’,DB::raw(‘sum(sub_total) as total’),’products.product_slug’) ->where([‘user_id’=>$user_id]) ->groupBy(‘user_id’) ->get(); Sourc..

Read more

After hosting my Laravel project on cPanel, every time I create an user using Laravel default Register controller the Id becomes 0. my migration: public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’); $table->string(‘name’); $table->string(’email’); $table->timestamp(’email_verified_at’)->nullable(); $table->boolean(‘is_admin’)->nullable(); $table->string(‘dept’); $table->string(‘batch’); $table->string(‘roll’); $table->integer(‘phone’); $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); } my controller: protected function create(array $data) { return ..

Read more

Im currently reffering a ecommerce lesson using laravel 8.when creating categories for the products im keep getting this error message while migrating. SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table if exists products) This is my create_products_table <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use ..

Read more

I have already a session table called ci_sessions with this structure CREATE TABLE `ci_sessions` ( `id` varchar(128) NOT NULL, `ip_address` varchar(45) NOT NULL, `timestamp` int(10) unsigned NOT NULL DEFAULT ‘0’, `data` mediumblob NOT NULL, PRIMARY KEY (`id`), KEY `ci_sessions_timestamp` (`timestamp`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; How can i use this on Laravel to store my session ..

Read more

i am currently working on a project which will be handling large amount of data to be written and retrieved from the mysql on daily basis. currently i have data distributed among three tables according to there context. 1st table is very lightweight as it contain identifiers and timestamps only. second one is bit large ..

Read more

I want to count last_status from history. Here is it a table looks like ——– p_table ——– id name —————- history_p_table —————- id p_id (many to one p_table) status_id (many to one status_table) date_history order_history ———— status_table ———— id name p_table hasMany history_table and history_table belongsto status_table I want to get all count of status ..

Read more

I ran this query $data = Visitor::where(‘created_at’, ‘>’, now()->subWeek())->get()->pluck(‘created_at’); dd($data); I got this IlluminateSupportCollection {#521 ▼ #items: array:72 [▶] } I have 72 visitors since last 7 days. How do I modify my query to get something like this ? Note 0-6 day of week, sunday(0) & saturday(6) { 0:10, 1:10, 2:10, 3:10, 4:10, 5:10, ..

Read more

Let’s say I have a model Foobar with relationships named baz and quux. I would like to query all Foobar that do not have either relationship; meaning I only want to select Foobar where BOTH baz and quux relationships are absent. I tried four different ways: // Attempt 1 Foobar::doesntHave(‘baz’)->doesntHave(‘quux’)->get(); // Attempt 2 Foobar::doesntHave(‘baz’, ‘AND’)->doesntHave(‘quux’, ..

Read more

Please see edit at bottom of question. Let’s say I have a model Foobar with relationships named baz and quux. I would like to query all Foobar that do not have either relationship; meaning I only want to select Foobar where BOTH baz and quux relationships are absent. I tried multiple different ways: // Attempt ..

Read more

I’m struggling with implementing SQL query into my php code, the query: select template_id, min(created_at) as created_at from ( select distinct root_template_id as template_id, date_created as created_at, response_id as response_id from db.score inner join db.users ON db.score.supplier_id = db.users.old_id inner join db.acc ON db.acc.user_id = db.users.id where db.acc.account_id = 25) as T group by template_id ..

Read more

I’m trying to get all item series from a deposit but the deposit id is on a related table. On this function i’ll list all the series between two sequences requested public function getSeries($params = []) { $data = collect($params); $inicio = $data->only(‘serie_in’); $fim = $data->only(‘serie_fi’); $depOrigem = $data->only(‘id_origem’); $series = []; for($i = $inicio; ..

Read more

I’m trying to get all items’ series from a deposit but the deposit id is on a related table. On this function i’ll list all the series between two sequences requested public function getSeries($params = []){ $data = collect($params); $inicio = $data->only(‘serie_in’); $fim = $data->only(‘serie_fi’); $depOrigem = $data->only(‘id_origem’); $series = []; for($i = $inicio; $i ..

Read more