lundi 12 décembre 2022

Single Signin For All Subdomain Or Projects?

Hy All Hope All Are Fine. First Of All Sorry For My English And I Am Totally New And didn't Know About Php My Sql Etc, So Lets Start My Questions With Detail I Purchased too many Projects subdomain1.maindomain subdomain2.maindomain subdomain3.maindomain subdomain4.maindomain May Be In Future I Will Add More Now Simply I Want Single Login For All Subdomains, Mean That User Can Signup In One Of Any Domain But Can Login For All Subdomain As Same Signup For any One Of Above Domain. My Sql Database User Is Same But Mysql Database Is Different One From Other Every Subdomain or Domain Has It's Own Database. Please Tell Me Is It Possible To Login As A One???? Please If It Is Possible Share With Detail Because I Am New. I Did't Try Any Method



via Chebli Mohamed

dimanche 11 décembre 2022

What would be the proper steps to upgrade laravel version 5 to latest version 9

I have an old project which I developed in Laravel 5.3 and I want to upgrade the project to Laravel v9. What are the steps to upgrade?

What I have seen so far on the internet and from my knowledge:

Upgrade to each higher version step by step e.g 5.3 to 5.4 ... 6 to 7 to 8 to 9

I am running php 8 on my macos. And currently, my code is not running because of deprecated methods in php 5.6 that my Laravel 5.3 is using.

How to upgrade properly?

My composer.json file is

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "appzcoder/crud-generator": "^2.0",
        "laravelcollective/html": "5.3.*",
        "doctrine/dbal": "^2.5",
        "maatwebsite/excel": "~2.1.0",
        "predis/predis": "~1.0",
        "guzzlehttp/guzzle": "~4.0",
        "laravel/scout" : "^2.0",
        "algolia/algoliasearch-client-php": "^1.17",
        "fx3costa/laravelchartjs": "^2.2",
        "gloudemans/notify": "^1.0",
        "pda/pheanstalk": "~3.1"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "allow-plugins": {
            "kylekatarnls/update-helper": true
        }
    }
}



via Chebli Mohamed

vendredi 9 décembre 2022

Replacing Google OAuth API in Laravel

I have an app that I was tasked with to renew. However, the app runs a Google OAuth API to authenticate the users. However, this instance of the API no longer works as the company has changed name and thus the old mail domain no longer exists.

E.g: name@companyname.com

Is there a way for me to change the instance of the api so it will allow any gmail to get in.

here's my current controller for the oauth

public function checkUserByToken($social_token)
    {
        $client  = new \Google_Client(['client_id' => env('GOOGLE_CLIENT_ID', '')]);
        $payload = $client->verifyIdToken($social_token);
        if ($payload) {
            $validator = Validator::make($payload, [
                'email' => 'required|email|regex:/(.*)oldcompany.com$/i',
            ]);
            if ($validator->fails()) {
                return false;
            }
            $user = User::where('email', $payload['email'])->first();
            if (!$user) {
                $data = [
                    'name'      => $payload['family_name'],
                    'full_name' => $payload['name'],
                    'email'     => $payload['email'],
                    'password'  => bcrypt(str_random(8)),
                ];
                $user = $this->createUser($data);
            }
            $user->forceFill([
                'email' => $payload['email'],
                'email_verified_at' => Carbon::now(),
            ])->save();
            $tokenResult = $user->createToken('Personal Access Client');
            $token = $tokenResult->token;
            $token->expires_at = Carbon::now()->addMonth();
            $token->save();
            $data = [
                    'access_token' => $tokenResult->accessToken,
                    'token_type'   => 'Bearer',
                    'expires_at'   => Carbon::parse($tokenResult->token->expires_at)->toDateTimeString(),
                    'full_name'    => $payload['name'],
                    'avatar'       => $payload['picture'],
                    'role'         => $user->role,
                    'section'      => isset($user->section)?$user->section->name:"",
                    'id'           => $user->id
            ];
            return $data;
        } else {
            return false;
        }
    }

I have tried replacing the google OAuth API in .env and change

 $validator = Validator::make($payload, [
                'email' => 'required|email|regex:/(.*)oldcompany.com$/i',
            ]);

to

 $validator = Validator::make($payload, [
                'email' => 'required|email|regex:/(.*)newcompany.com$/i',
            ]);

no avail as I think the google API outside of sending back auth token also send back something else but I'm not sure what it is.



via Chebli Mohamed

Controller does not exist in laravel 5.6

I have this error where it said that the controller does not exist

My routes

use App\Http\Controllers\PasienController;  
Route::resource('/pasien', PasienController::class)->only(['index']);

The controller

<?php

namespace App\Http\Controllers;

use App\Token;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use RealRashid\SweetAlert\Facades\Alert;

class PasienController extends Controller
{
    public function index(Request $request)
    {
        $patient = null;
        if (isset($request->nik)) {
            $response = $this->patient_by_nik($request->nik);
            $data = $response->getData();
            if ($response->status() == 200) {
                if ($data->total) {
                    $patient = $data->entry[0]->resource;
                    Alert::success($response->statusText(), 'Pasien Ditemukan');
                } else {
                    Alert::error('Not Found', 'Pasien Tidak Ditemukan');
                }
            } else {
                Alert::error($response->statusText() . ' ' . $response->status());
            }
        }
        
}

I was trying to get data from an API and return the data



via Chebli Mohamed

mercredi 7 décembre 2022

The "--path" option does not exist

The "--path" option does not exist.

Artisan::call("migrate --path=database/migrations/tenant")

i updated Laravel from 5.8 to laravel 8

i don't know that wrong

Artisan::call("migrate") work fine



via Chebli Mohamed

page not opening when click the post

I am newbie in development please help,Do not judge me. Remember everyone starts from 0.

When I click my ticket it is not opening specific page while click link of my ticket it shows in link correct ticket id but page not opening "404 not found"

Ticket.blade.php

`

                        
                                <tr>
                                                                     
                                                                     
                                    @foreach ($ticketsinfos as $ticketinfo)
                                    <td>IR-173049</td>
                                    <td>Dito Katsarava</td> 
                                    <td></td>
                                    
                                    <td><a href="/tickets/show/"></a></td>
                                    
                                    <td><button class="btn btn-danger btn-sm" type="button">Action Needed<br></button><br></td>
                                    <td>Tako Kiknadze</td>
                                    <td></td>
                                    <td></td>
                                </tr>

                                @endforeach  
                              
                                </tr>

`

web.php

`

<?php

use App\Http\Controllers\AdminsUserController;
//use App\Http\Controllers\UserController;
//use App\Http\Controllers\CompaniesController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\TicketsController;
//use App\Models\AdminsUser;
//use App\Models\Companies;
use Illuminate\Support\Facades\Route;

/*
|----------------------------------------------z----------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::resource('/dashboard', DashboardController::class);

Route::resource('/tickets', TicketsController::class);

Route::resource('/admin/users', AdminsUserController::class);
// Route::resource('/companies', CompaniesController::class);




Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');


`

Controller

`

  public function show(Tickets $tickets)
    {
        //
        $tickets = Companies::with('tickets')->get();

        $severities = Severities::with('severity')->get();
        
        $ticketsinfos = Tickets::with('companies')->findOrFail(2);
    
        

  
     return view('customer.index', compact($tickets))->with(['tickets' => $tickets])->with(['severities' => $severities])->with(['ticketsinfos' => $ticketsinfos]);

    //dd($ticketsinfos->toArray());
        
    }

`

When I 'dd' works

Thanks you.



via Chebli Mohamed

laravel Unique Validation on row where is_active is 1

I want to implement unique validation on one column but it should only check active rows of the table. so is there any way I can implement this logic using laravel validation?

Below is the logic I am using to check unique records but its not working.

unique:users,email,is_active,1


via Chebli Mohamed