mercredi 4 novembre 2020

External API auth should be a ServiceProvider or Controller in Laravel?

Im building an app using Laravel, that app will allow the customers to send and get contacts from/to Mautic (email marketing software) via API, but first the app need to get an autorization to use Mautic API and store the user credintals to database for future use.

This is an example for how i make an autorization to connect to that api

$settings = [
    'userName'   => '',             // Create a new user       
    'password'   => '',             // Make it a secure password
];

// Initiate the auth object specifying to use BasicAuth
$initAuth = new ApiAuth();
$auth     = $initAuth->newAuth($settings, 'BasicAuth');

and then i can get the contact by id using this

$api        = new MauticApi();  //This class is from the API package
$contactApi = $api->newApi('contacts', $auth, $apiUrl);
$response = $contactApi->get($id);

So my question is how can i organize that logic, should i just put all of it in a controller or it's better to create a service provider which should be responsible of the autorization and then return $auth handle that i can use then later for each customer, and if it's better to user the serviceprovider approch then i'm wondering how can i do that, should i just put the autorization logic in the boot method?



via Chebli Mohamed

mardi 3 novembre 2020

Class 'Doctrine\Inflector\InflectorFactory' not found

I have a Laravel project in production running in the Laravel version in 5.5.50

One of the team member made some changes to the code and pushed the code. And later when I pulled the code and run it. It generated an error

Interface 'Symfony\Component\Translation\Formatter\IntlFormatterInterface' not found

I solved this. The front end of the project worked fine. When I needed to login to the admin dashboard,the register page works fine. But when I submit the login credential I get the following error

FatalThrowableError (E_ERROR)
Class 'Doctrine\Inflector\InflectorFactory' not found

And I am not able to solve this. I tried composer update, the composer does get updated but the error is still there. The project worked just fine before the pull.



via Chebli Mohamed

How to access folders outside root directory in laravel? to be fetched with Vue

I'm trying to build a project. This project is contained in 2 seperate folders. The back-end is using laravel and the front-end is using Vue. The problem is, I need to fetch photos with vue from the laravel folder. Here is the project structure:

  • Project Folder
    • Laravel Folder
      • Media Folder (Contains images to be fetched with Vue)
    • Vue Folder

Currently here is the set up. When I execute the controller in laravel, it default accesses it's own public folder and creates a folder called media. is there a way to create a path for laravel that is outside it's own root folder?

What I'd like to happen is to set the upload path outside of the laravel folder and into the Vue folder so that Vue can fetch the data. Alternatively, If we could find a way where Vue can access files outside of it's own directory, that could be a solution too.

$upload_path = 'media';


via Chebli Mohamed

how to make filter for food by category and subcategory , and once i press on any category i get its food dishes

using these tables I need to make category filter

Food Table: Migration

   $table->bigIncrements('id');
            $table->unsignedBigInteger('category_id')->nullable();
            $table->unsignedBigInteger('image_id')->nullable();
            $table->string('name')
            $table->float('price',9,2)->default(0);
            $table->float('offer_price',9,2)->nullable()->default(0);

            $table->boolean('visible')->default(0);
            $table->timestamps();

categories table: Migration


Schema::create('categories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('parent_id')->nullable();
            $table->unsignedBigInteger('image_id')->nullable();
            $table->boolean('visible')->default(0);
            $table->timestamps();
        });

Food Model relation

    public function category()
    {
        return $this->belongsTo(Category::class, 'category_id')->withDefault();
    }

Category Model relation

 public function food()
    {
        return $this->hasMany(Food::class)->orWhereIn('category_id' , $this->subcategory()->pluck('id')->toArray())->visible();
    }
    public function subcategory()
    {
        return $this->hasMany(self::class, 'parent_id', 'id');
    }
````[When clicking on any category it should show food, that related to the category I clicked on ][1]


  [1]: https://i.stack.imgur.com/zpVb8.png


via Chebli Mohamed

updated all dependencies in ubuntu sever but my Laravel showing only folders and files in ubuntu server?

I have spend days to find out why can't my site is loading with real content. my laravel project is showing only folders and files but i have install it on my ubuntu server with all supported package. please help requried . my site results.musom.edu.np



via Chebli Mohamed

lundi 2 novembre 2020

BelongsToMany Is Not supported for hybrid query constraints - mongodb laravel

I'm getting below error in my laravel application getting belongsToMany relationship data in the repository. The application only has MongoDB database only. no hybrid with MySQL or any other.

 message    "BelongsToMany Is Not supported for hybrid query constraints!"
    exception   "Exception"
    file    "/var/www/backend/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php"
    line    115

Repository code is like below.

$moduleInfo = $this->page->whereHas('section', function ($q) use ($module_id) {
            $q->whereHas('chapters', function ($r) use ($module_id) {
                $r->whereHas('modules', function ($s) use ($module_id) {
                    $s->where('_id', $module_id);
                });
            });
        })
            ->with([
                'section' => function ($q) {
                    $q->with([
                        'chapters' => function ($r) {
                            $r->with('modules');
                        }
                    ]);
                }
            ])
            ->get()
            ->toArray();

in Page Model

public function section()
    {
        return $this->belongsToMany( 'App\Models\Section', 'page_id', 'page_ids' );
    }

I'm using jenssegers/mongodb package to connect mongo DB and laraval version is 5.6 jenssegers/mongodb version is 3.4

Data seems fine. Does anyone know the reason for this issue?



via Chebli Mohamed

Images not serving in laravel after deploying to cpanel

We have deployed our project at cpanel, but after uploading the new added images are showing 404 error. We see image is uploaded in one folder, but not serving through public folder. It is working fine at local

What could be the possible solutions?

enter image description here



via Chebli Mohamed