mercredi 30 novembre 2022

getting error on server(aws) SyntaxError: Unexpected token '<', "

I have deployed my laravel application on AWS server(ubuntu). Application works fine. But when I upload images using custom modal popup, then i got the syntax error from vendors.js.

Here is the error getting from modal popup while uploading images: Here is the error getting from modal popup while uploading images

Can anyone tell about that, how i can resolve that? I am just stuck from last two days.

I have tried run on server npm i body-parser And also re-add the file of vendors.js But same result.



via Chebli Mohamed

mardi 29 novembre 2022

Fatal error: Uncaught ReflectionException: Class IlluminateContractsHttpKernel does not exist

Fatal error: Uncaught ReflectionException: Class IlluminateContractsHttpKernel does not exist in C:\xampp\htdocs\erc_new\vendor\laravel\framework\src\Illuminate\Container\Container.php:788 Stack trace: #0 C:\xampp\htdocs\erc_new\vendor\laravel\framework\src\Illuminate\Container\Container.php(788): ReflectionClass->__construct('IlluminateContr...') #1 C:\xampp\htdocs\erc_new\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('IlluminateContr...') #2 C:\xampp\htdocs\erc_new\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('IlluminateContr...', Array) #3 C:\xampp\htdocs\erc_new\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('IlluminateContr...', Array) #4 C:\xampp\htdocs\erc_new\public\index.php(52): Illuminate\Foundation\Application->make('IlluminateContr...') #5 C:\xampp\htdocs\erc_new\server.php(21): require_once('C:\xampp\htdocs...') #6 {mai in C:\xampp\htdocs\erc_new\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 788

auto it is showin the Kernel error. thought i have not made any changes. i have already tried checking the Kernel.php files. more over i have already deleated the vendor and composer.lock file and install the composer . But also getting the the above error.

Moreover I also have deleted the every things that recedes on bootstrap/cache/



via Chebli Mohamed

Laravel 8 - search paginate ( withQueryString ) not working on table when searching NUMBERS on row integer

i can't search when it comes to searching NUMBERS on row int (price), but when searching like String number on row string (name) it's working fine

like this in my table row here is my Product table

category_id
"56"
user_id
"1"
name
"555"
description
"fruit"
price
555

when i am searching the name row "555" it's working fine beacuse its a string. but when it comes to price i can't search it because it's int

here is my code for controller searching

public function index(Request $request){
    $user = Auth::user()->id;
    if($request->search){
        $search = $request->search;
        $products = Products::with('category')
        ->where('name','like',"%$search%")
        ->orWhere('price','like',"%$search%")
        ->where('user_id',$user)->paginate(10);
    }else{
        $products = Products::with('category')->where('user_id',$user)->paginate(10);
    }
      return view('client.product.index',['products'=>$products]);
}

here is my blade

    <form class="w-full" action="">
        <i class="fa fa-search"></i>
        <input placeholder="Search"  type="search" name="search">     
        <button type="submit">Search</button>
    </form>

@foreach ($products as $product)
    <p></p>
    <p></p>
@endforeach



via Chebli Mohamed

lundi 28 novembre 2022

How to sort parent data based on child column detial in laravel 5.4?

I have 3 way relationship firstl i have get code like this in a controller

Trial::with('subjects')->where('source_id', $sourceId)->get()->toArray()

Now I want to sort subject.reactions on desc order of subject.reactions.accounts.nb_followers column. I tried to use orderby on relationship but it does not work because it sorting account indsted on reactions. I want to sort reaction based on value of "nb_followes" column present inside account table.

Trail Model

class Trial extends Model
{
    use HasFactory;
    public $table = 'trials';

    public function subjects()
    {
        return $this->hasMany(Subject::class, 'trial_id')->with(['reactions', 'news'])->withCount('reactions');
    }
  } 

Subject Model

class Subject extends Model
{
    use HasFactory;
    public $table = 'subjects';

    public function reactions()
    {
        return $this->hasMany(Reaction::class, 'subject_id', 'id')->with(['accounts' => function ($q) {$q->orderBy('nb_followers', 'DESC');}])->where('twitter_error', 0)->where('active', 1)->orderby('key_reaction', 'DESC');
    }

    public function news()
    {
        return $this->hasone(News::class, 'id', 'news_item_id');
    }

Reaction Model

class Reaction extends Model
{
    use HasFactory;

    public $table = 'reactions';

    public function accounts()
    {
        return $this->belongsTo(Account::class, 'account_id', 'id')->where('name', '!=', '');
    }

Thank you in Advance.



I want to sort reactions based on account table's column yes i cant use simple eloquent query because it will not create a structure that i want so that's why i created these relationships.


via Chebli Mohamed

vendredi 25 novembre 2022

500 error when image upload with Laravel 5.8 on nginx server

I'm getting 500 internal error when i try to upload 20kb image file.

I was checked following steps for finding to solution but it doesn't work :

  • I have hidden input for csrf token
  • I checked my storage and bootstrap folder for chmod 755 but they have permission.
  • My public folder has 777 permission
  • When i change app_env=local and app_debug=true there is no diffrent error.
  • There is no error log in storage/logs
  • When i try to submit form without image it worked.
  • there is no specific error in nginx logs (var/log/nginx/error.log)

I'm trying to upload image with laravel form in nginx server but i get 500 internal server error.



via Chebli Mohamed

How can I pass params at access point of GraphQL such as {url}/graphql?development=true by using lighthouse in laravel

How can I pass params at access point of GraphQL such as {url}/graphql?development=true by using lighthouse in laravel. if development is true i want to use different database in laravel.

http://127.0.0.1:8000/graphql?development=true

its working but graphql does not getting development params



via Chebli Mohamed

jeudi 24 novembre 2022

Error Laravel\Socialite\Two\InvalidStateException In the return method from the Google side

I want use Socialite package but receive in Error !

controller codes :

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\User;
use Laravel\Socialite\Facades\Socialite;

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

    public function callback()
    {
        // when i dd() here i see in the answer in the browser.
        $googleUser = Socialite::with('google')->user();
        // but dd in here isn't working!
       
        $user = User::where('email', $googleUser->email)->first;

        if ($user) {
            auth()->loginUsingId($user->id);
        } else {
            $newUser = User::create([
                'name' => $googleUser->name,
                'email' => $googleUser->email,
                'password' => bcrypt(\Str::random(16)),
            ]);
            auth()->loginUsingId($newUser->id);
        }
        return $this->redirect('/');
    }
}

in web.php :

Route::get('auth/google', 'Auth\GoogleAuthController@redirect')->name('auth.google');
Route::get('auth/google/callback', 'Auth\GoogleAuthController@callback');

laravel version : 6.20.26

php version : 7.2.5

please help me. tnks

===============================================================

I try this (https://stackoverflow.com/a/37849202/20355717) :

Socialite::driver('google')->stateless()->user()

but in did't work for me and given an anothe error ! :

GuzzleHttp\Exception\RequestException

cURL error 77: error setting certificate verify locations: CAfile: /path/to
/downloaded/cacert.pem CApath: none (see https://curl.haxx.se/libcurl
/c/libcurl-errors.html) for https://www.googleapis.com/oauth2/v4/token


http://localhost:8000/auth/google/callback?authuser=0&code=4%2F0AfgeXvucuWTlboWqaMwf2bkBe0AHjbPEJd-
2e7cQdlSN345_3imguhVT_1PQ8fa3ISoHSA&prompt=consent&
scope=email%20profile%20openid%20https%3A%2F
%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20https%3A%2F
%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&
state=axIlfjFkns6vWNJIX2uJMuMKNiYFfy7cKiE8Xr8W 



via Chebli Mohamed