Category : laravel-models

I have setup the project on the subdomain like https://example.com/newapi. Also i have setup the module in the project OrderManagement with command composer require nwidart/laravel-modules it has created all the file structure in the OrderMangement folder. Also i can use the routes with https://example.com/newapi/ordermanagement But facing issue assets with laravel mix and it’s showing the ..

Read more

I want to use Auth user in the global scope User.php public function scopeActive($query) { return $query->where(‘accessed_id’, auth()->user()->accessed_id); } protected static function boot() { parent::boot(); static::addGlobalScope(‘customer_user’, function (Builder $builder) { if(auth()->check()){ // check user is auth or not $builder->active(); } }); } I am unable to get auth user in scope because the scope was ..

Read more

MySQL structure id key display_name value details group created_at updated_at Laravel resource index public function index() { $settings = Setting::groupBy(‘group’)->select(‘id’,’group as name’)->orderBy(‘id’, ‘ASC’)->get(); return view(‘settings.general’), compact(‘settings’)); } When I run the code its how error : SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and ..

Read more

I used laravel resources for my api responses and added paginate method. Upon using paginate method I always get a result like this where laravel by default gives three keys namely "data", "links" and "meta". But I want to change the resource to my own need. { "data": [ { "id": 1, "name": "Eladio Schroeder ..

Read more

There are two models BoardArticle and BoardArticleLocation. $articles = BoardArticle::where(‘board_id’, $board_id) ->orderBy("id", ‘desc’) ->paginate(20); $boardlocation = BoardArticleLocation::select(‘location_top as top’, ‘location_top_text as text’) ->addselect(DB::raw(‘CONCAT("[", group_concat(location_sub), "]") as sub’)) ->where(‘board_article_id’, $id) ->groupby(‘location_top’) ->get(); So, These are the ways I tried. $articles = BoardArticle::where(‘board_id’, $searchKey, $board_id) ->select(‘board_articles.*’) ->addselect(DB::raw(‘CONCAT("[", group_concat(DISTINCT location_top_text), "]") as location_text’)) ->leftjoin(‘board_article_locations’, ‘board_articles.id’, ‘=’, ‘board_article_locations.board_article_id’) ->groupby(‘board_articles.id’) ..

Read more

I have Bank table and transaction table. The relationship is one-to-many, so a bank may have many transactions. Transaction table has the bank foreign key(bank_id). and each transaction has a column ‘type’ which is either credit or debit. I want to show each bank balance based on its transactions. Here are my questions: How to ..

Read more

I´m traying to relatting Models in my code for get clinic´s data. My application it´s for fisioterapy clinic. I have one Model to patients and other to companies. In my DB patients it´s relationed with cpmpanies for column company and in my model patient i have this: /** * @return IlluminateDatabaseEloquentRelationsBelongsTo **/ public function company() ..

Read more

I’m laravel beginner and use L8. i have a category table and it has parent_id for my subcategories . i use one table and model to CRUD them but my controller and view are separate. it means : categories table Category model categoryController SubCategoryController categories.blade sub_categories.blade in my subcategory-index.blade.php i want to show categories but ..

Read more

i need to make the post accepts as many language as i need so i have tow models post and language in post model: public function languages(){ return $this->belongsToMany(AppModelsLanguage::class); } in my language model : public function posts() { return $this->belongsToMany(AppModelsPost::class); } post migration : Schema::create(‘posts’, function (Blueprint $table) { $table->id(); $table->string(‘title’); $table->text(‘body’); $table->boolean(‘puplished’)->default(false); $table->bigInteger(‘user_id’)->unsigned(); ..

Read more