jeudi 9 septembre 2021

Call to undefined method App\Models\Meevo::getCategories()

$categories = $this->categoryRepository->getCategories($request); // $categories = Category::where('salon_id',$request->salon->salon_id)->with('services')->get(); if (!$request->session()->has('user') && $request->salon->show_login_home) { return view($request->salon->view_path . '.login'); } else { return view($request->salon->view_path . '.home', compact('categories')); }



via Chebli Mohamed

Callback 404 not found in login with google with Socialite

I have this link on my modal popup

<li><a href="" target="_blank"><i class="fab fa-google-plus-g"></i></a></li>

and routes is

Route::get('google', 'SocialiteAuthController@googleRedirect')->name('auth/google');
Route::get('/auth/google-callback',  'SocialiteAuthController@loginWithGoogle');

enter image description here

Services.php

'google' => [
    'client_id' => 'XXXXXXXXXXXXXXXX.apps.googleusercontent.com',
    'client_secret' => 'XXXXXXXXXXXXX',
    'redirect' => 'http://localhost:8000/login/google/callback',
],

Controller:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\User;
use Socialite;
use Illuminate\Support\Facades\Auth;
use Exception;

class SocialiteAuthController extends Controller
{
    public function googleRedirect()
    {
        return Socialite::driver('google')->redirect();
    }

     /**
     * Facebook login authentication
     *
     * @return void
     */
    public function loginWithGoogle()
    {
        try {
            $googleUser = Socialite::driver('google')->user();
            $user = User::where('google_id', $googleUser->id)->first();

            if($user){
                Auth::login($user);
                return redirect('/home');
            }

            else{
                $createUser = User::create([
                    'name' => $googleUser->name,
                    'email' => $googleUser->email,
                    'fb_id' => $googleUser->id,
                    'password' => encrypt('test@123')
                ]);

                Auth::login($createUser);
                return redirect('/home');
            }

        } catch (Exception $exception) {
            dd($exception->getMessage());
        }
    }
}

Guard :

 'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'user' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

but when i login i'm getting this page 404 not found

enter image description here

Any solution, Thanks



via Chebli Mohamed

get value from an input using javascript and laravel

i need to get the value of the input with javascript.

Input:

<input id="user_id" value="5" name="user_id" type="hidden">

Controller:

 public function savetoken(Request $request)
{


    
    $this->validate($request, [
        'user_id'     =>  'required',
        'token'  =>  'required',
       ]);

        Notificaciones::create([
          'user_id'  => $request->user_id,
          'token' => $request->token
        ]);
  
        return back()->with('success', 'token saved successfully!');
}

How to get the Value of the Input that is Hidden? Javascript:

 function guardarToken(token){
    var formData=new FormData();
    formData.append('token',token);
    formData.append('user_id', user_id);

    var config = {
        headers: {
            'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"').content

        } 
    }

    axios.post('/token',formData, config).then( respuesta=>{
        console.log(respuesta);
    }).catch( e=>{
        console.log(e);
    });
}

I tried this way but I have not succeeded

help please



via Chebli Mohamed

mercredi 8 septembre 2021

What is the proper syntax to exclude rows that have a specific ID, but lack a row in a related table with a value in a column on that row?

Currently working on getting my head around the ordering of things, not even with laravel at first, but sql. Though the end goal is to use eloquent.

There are 2 conditions for the rows that need to be excluded. If I'm fetching the rows from TableA..

1) TableA with the column status_id (or TableC.id) has to have lets say a value of 1.

2) TableB has to have an instance for that TableA.id where status_id (or TableC.id) is lets say 2.

Been looking at whereNotIn, whereExists and when for a while now, but can't wrap my head around what is correct for the situation and how it should look like.

Still learning about sql queries and I am very grateful for any tips on this dilemma.



via Chebli Mohamed

How to convert stream to download laravel

            $stream = fopen('data://text/plain;base64,' . base64_encode($response),'r');
            $stat = fstat($stream);
            $size = $stat['size'];

            $type = "video/mp4";
            $start = 0;
            $length = $size;
            $status = 200;

            $headers = ['Content-Type' => $type, 'Content-Length' => $size, 'Accept-Ranges' => 'bytes'];

            return response()->stream(
                function() use ($stream, $start, $length) {
                    fseek($stream, $start, SEEK_SET);
                    echo fread($stream, $length);
                    fclose($stream);
                }, $status, $headers
            );

the above is working to stream a video but I need to download the video directly instead... any suggestions, please



via Chebli Mohamed

assign and return specific data based on user role

I like to understand how I can assign each user who has the role we say that each agent with its own interface, indeed I am applying a solution which set up a system in which an administrator creates a new user with the agent role, an agent can create users with the user role, so we suppose that an admin creates 2 agents: Agent A and agent B each agent accesses the same interface but each one has its own users, I don't like to return all the users of the database in the interface of all the agents, so if agent A is authenticated the interface retrieves only the users who are added by agent A and the same thing for agent B is there a solution? im in laravel 5 here is mu User.php model

namespace App\Models;

use App\Models\Formatters\Formatter;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable 
{
    
   

   
    const ROLE_USER  = 'USER';
    const ROLE_ADMIN = 'ADMIN';

 

   
    /**
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'last_login_from', 'role', 'status', 'last_login_at', 'referrer_id'
    ];

    /**
     * 
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token', 'status', 'role', 'last_login_from', 'referrer_id', 'referrer', 'totp_secret'
    ];


   
  
    /**
     * User account
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function account()
    {
        return $this->hasOne(Account::class);
    }

    /**
   
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function referrer()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Users, referred by current user (referees)
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function referees()
    {
        return $this->hasMany(User::class, 'referrer_id');
    }

  

    /**
     * User games
     *
     * @return $this
     */
    public function games()
    {
        return $this->hasManyThrough(Game::class, Account::class)->where('status', Game::STATUS_COMPLETED);
    }

    /**
     *
     * @param $role
     * @return bool
     */
    public function hasRole($role)
    {
        return isset($this->role) && $this->role == $role;
    }

    public static function roles()
    {
        return [ self::ROLE_USER, self::ROLE_ADMIN];
    }


    /**
     *
     */
    public function admin()
    {
        return $this->hasRole(self::ROLE_ADMIN);
    }

   

}


via Chebli Mohamed

delete code in string with loop when read PDF with php

I´m traying to read PDF file with this library, \Smalot\PdfParser\Parser(); in laravel 5.6

i´m reading all my pdf ok, i´m getting all my content ok. i´m deleting headers from my PDF and i´m inserting by line in array.

and this it´s data:

    [0] =>  MARTIN CARRILLO MARIA ESMERALDA ALHAMBRA 10 958 54 38 93
    [1] => 1745591 ESPIGARES DIAS JOSE ANTONIO ALHAMBRA 11 958 54 33 32
    [2] => 1770062 GUTIERREZ TITOS JOSE MANUEL ALHAMBRA 12 958 54 04 10
    [3] => 1793228 MARTIN COBOS ANTONIO ALHAMBRA 18 958 54 33 28
    [4] => 1768807 GOMEZ CARRILLO JOSE ALHAMBRA 20 958 54 32 72
    [5] => 1830072 RODRIGUEZ RUANO BUENAVENTURA ALHAMBRA 21 958 54 35 86
    [6] => 1759534 GARCIA ARIAS MARIA ISABEL ALHAMBRA 22 958 54 07 87
    [7] => 1831938 RODRIGUEZ JIMENEZ MIGUEL ALHAMBRA 27 958 54 08 77
    [8] => 1722022 GUTIERREZ FERNANDEZ AMANDA HILDA ALHAMBRA 3 958 49 98 62
    [9] => 1746872 DIAZ FLORIAN DOLORES ALHAMBRA 30 958 54 33 99
    [10] => 1817587 PEREZ LASTRA SAUL ADAN ALHAMBRA 32 958 54 31 46
    [11] => 1724006 AMIGO MOLINA MARIA MATILDE ALHAMBRA 35 958 54 31 91
    [12] => 1745604 ESPIGARES GOMEZ JORGE ALHAMBRA 37 958 54 02 22
    [13] => 1745595 ESPIGARES ESPIGARES JOSE ALHAMBRA 40 958 54 31 83

i need delete firt numbers, it´s code from this client. i´m doing this for delete code, but always it´s doing in firts element.

This is my code to tray delete my code from all string...

// loop to get data line
for($i=0; $i<count($dataByLine); $i++){
   // delete code
   $numberCode = stripos($dataByLine[$i], " ");
   $codeClear = substr($text, 0, $numberCode);
   $dataByLine = str_replace($codeClear, "", $dataByLine);

   print_r($dataByLine);
}

this print_r() it´s my first content array. As you can see in my array, first element it´s without code.. but the rest, have code.

how i can to delete all code from this string¿?

thanks for help and read. Sorry for my english

updated

// loop to get data line
foreach($dataByLine as &$line){                        
   //$line = preg_replace('/^[\d]+/','',$line);
   $line = ltrim($line,"0123456789");

   array_push($dataList, $line);
}

print_r($dataList);

this it´s result:

    [0] =>  1794707 MARTIN CARRILLO MARIA ESMERALDA ALHAMBRA 10 958 54 38 93
    [1] =>  ESPIGARES DIAS JOSE ANTONIO ALHAMBRA 11 958 54 33 32
    [2] =>  GUTIERREZ TITOS JOSE MANUEL ALHAMBRA 12 958 54 04 10
    [3] =>  MARTIN COBOS ANTONIO ALHAMBRA 18 958 54 33 28
    [4] =>  GOMEZ CARRILLO JOSE ALHAMBRA 20 958 54 32 72
    [5] =>  RODRIGUEZ RUANO BUENAVENTURA ALHAMBRA 21 958 54 35 86
    [6] =>  GARCIA ARIAS MARIA ISABEL ALHAMBRA 22 958 54 07 87
    [7] =>  RODRIGUEZ JIMENEZ MIGUEL ALHAMBRA 27 958 54 08 77
    [8] =>  GUTIERREZ FERNANDEZ AMANDA HILDA ALHAMBRA 3 958 49 98 62
    [9] =>  DIAZ FLORIAN DOLORES ALHAMBRA 30 958 54 33 99


via Chebli Mohamed