mercredi 8 juin 2022

View [views.create] not found [closed]

I do not even know what should I do more?

this is my web.php

use App\Http\Controllers\HomeController;

 Route::get('/home', [HomeController::class,'index']); // have another version no worry

This is controller:

class HomeController extends Controller
{

    public function index()
{
    //
    return view('views.create');
}

this is view:

create.blade.php  // in views folder

sdhfbskdfnkds

What did I miss? Why does appear this error? I did lots of things:

composer update
php artisan config:cache
php artisan cache:clear
checked folders - views, sessions,cache in storage
re installed laravel 


via Chebli Mohamed

Unable to fetch results from hasManyJson Using staudenmeir / eloquent-json-relations

I have been working on two tables Category & Product. In Category Model I have a relationship like

class Category extends Model
{
  use \Staudenmeir\EloquentJsonRelations\HasJsonRelationships;
  public function products(){

    return $this->hasManyJson(Product::class,'category_ids[]->id');
  }
}

In Products Model I have a relationship like

class Product extends Model
    {
      use \Staudenmeir\EloquentJsonRelations\HasJsonRelationships;
      protected $casts = [
          'category_ids'=>'json', 
      ];
      public function products(){

        return $this->belongsToJson(Category::class,'category_ids[]->id');
      }
    }

Now in my controller when I'm doing trying to get count of each categories product, it is giving me Empty results, below is my controller code.

public function two_category()
{
    $list = Category::where('home_status', true)->get();
    foreach($list as $ls){
        echo $ls->name.'    '.count($ls->products).'<br>';
    }
    dd('ended');
   }

This is giving -

Category1 0

Category2 0

And finally this is how my column in product table looks like. Category id column in json



via Chebli Mohamed

lundi 6 juin 2022

Laravel Job Withcount Parameter not Accessible in job Laravel 5.6

Hii I created a job to send mail. I execute a query in the controller using withCount() and am able to get the count parameter inside the controller but while I am parsing the same data to the job and assign to a local variable in constructer then I use a local variable inside the handle method count parameter was missing in my local.

I am using SYNC as QUEUE_DRIVER and code files below mention

Controller

 $confernceIterationData = ConferenceIteration::with('AbstractNews')->withCount('AbstractNews')->where('id', $unserializeData['confid'])->first();
              
 $this->dispatch(new SendtronAutomatedEmailJob($confernceIterationData, $unserializeData, $attachments));

Controller Output of dd($confereceIterationData)

array:42 [
    "id" => 9085
    "conference_iteration_id" => "e3f65fda-7776-4e64-82d8-b5f1289141e2"
    "conference_id" => 259
    "name" => "American Association of Cancer Research Annual Meeting 2022"
    "acronym" => "AACR 2022"
    "abstract_news_count" => 8339
  ]

Job

<?php

namespace App\Jobs;

use App\Mail\SendTronAutomatedMail;
use App\TeamConferences;
use App\User;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;

class SendtronAutomatedEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * conference Iteration data
     *
     * @var object
     */
    protected $confrenceData;

    /**
     * Planner Form Data
     *
     * @var array
     */
    private $formData;

    /**
     * attchement files
     *
     * @var array
     */
    private $files;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($confrenceData, $formData, $files)
    {
        $this->confrenceData = $confrenceData;
        $this->confrenceData->abcount = $confrenceData->abstract_news_count;
        $this->formData = $formData;
        $this->files = $files;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        dd($this->confrenceData);

        $request = $this->formData;
        $i = 0;
        $users = User::select('email')->distinct()->wherehas('teams', function ($q) use ($request) {
            $q->whereIn('id', $request['teams']);
        })->pluck('email')->toarray();

        $subject = $this->confrenceData->acronym . " Conference Planner (" . $this->confrenceData->data_status . ")";

        

        $this->extractConfenceData($this->confrenceData);

      
 
        // dd($this->confrenceData->AbstractNews_count);

        $count = count($users);
        foreach ($users as $user) {
            Log::channel('sendtron_email')->info('Authomated Mail Send To .', ['id' => $user]);

            Mail::to($user)->send(new SendTronAutomatedMail($request['content'], $subject, $this->files));
            if (++$i === $count) {
                unset($users);
                TeamConferences::where('conference_iteration_id', $request['confid'])->whereIn('team_id', $request['teams'])->update(['last_mail_sent' => Carbon::now()->toDateTimeString()]);
                Storage::disk('s3SendTron')->delete(array_column($this->files, 's3path'));
            }
        }

    }
}

If we dd($confrenceData) in constructor we get the attribute abstract_news_count as mention in controller output.

but at the same time if we dd($this->confrenceData) we unable to get abstract_news_count



via Chebli Mohamed

laravel old env file is downloading while mywebsite/.env in shared hosting in laravel 5.6 in production mode

I am using laravel 5.6 in my shared hosting website. my project .env file is downloading while mywebsite/.env in production mode. The old env file is downloading means I was changed the env file content but downloading the old env file which is not available in my project. I have use the below code in .htacceses but still downloading <Files .env> order allow,deny Deny from all



via Chebli Mohamed

dimanche 5 juin 2022

image not display in admin panel

Image not display why in laravel, what is the issue controller nd blade is added Controller code

 try{

      $file=$request->file('image');
      $filename=$file->getClientOriginalName();
      $imgname = uniqid().$filename;

      $input['image']= $imgname;
      $destinationPath=public_path('upload/image/');
      $request->file('image')->move($destinationPath, $imgname);

  
        Auth::user();
        $article =  new Article();
        $article -> user_id=Auth::user()->id;
        $article -> title=$request->get('title');
        $article -> description=$request->get('description');
        $article-> image = $filename;
        $article -> status=$request->get('status');
        $article->save();
    $request->session()->flash('alert-success','article has been sucessfully created.');
    return back()->with('success', 'Article created successfully.');   
    }
catch(ModelNotFoundException $exception){
   // do task when error
    return back()->withError($exception->getMessage())->withInput();    }

}

in blade file print this code

 <td><img src=""
                                            width="500px"></td>


via Chebli Mohamed

jeudi 2 juin 2022

Laravel how to count each rows ID on tables relationship

so i have a 5 tables in my database with pivot, Countries, Cities, Shops, Users, shop_employee their relationship is this

Countries  | Cities      | Shops     | shop_employees| Users 
 id        | country_id  | city_id   |  shop_id      | id
                                        employee_id

my goal is i want to count each City, shop, employees in Country

this is my controller

class CountryController extends Controller
{
    public function country(){
       $countries = Country::with(['cities.shops.employees'])->get();
       return view('country',['countries'=>$countries]);
    }
}

this is my model Country

class Country extends Model
{
    public function cities(){
        return $this->hasMany(City::class);
    }
}

this is my model City

class City extends Model
{
    public function shops(){
        return $this->hasMany(Shop::class);
    }
}

this is my model Shops

class Shop extends Model
{
    public function employees(){
        return $this->belongsToMany(User::class,'shop_employees','shop_id','employee_id');
    }
}

this is my view

        <table class="table-fixed">
                <thead>
                  <tr>
                    <th class="py-2 px-2 border border-gray-300">Country</th>
                    <th class="py-2 px-2 border border-gray-300">City</th>
                    <th class="py-2 px-2 border border-gray-300">Shop</th>
                  </tr>
                </thead>
                <tbody>
                @foreach ($countries as $country)
                <tr >
                    <td class="py-2 px-2 border border-gray-300"></td>
                    <td class="py-2 px-2 border border-gray-300"></td>
                    <td class="py-2 px-2 border border-gray-300"></td>
                  </tr>
                @endforeach
                </tbody>
              </table>

i tried this code its working fine the City is counting


the output, in this output i want to display the count of shops and employee

enter image description here

but when im trying this code it gives me a error

  $country->cities->shops->count() or
  $country->cities->shops->employees->count() 

error: Property [shops] does not exist on this collection instance



via Chebli Mohamed

mercredi 1 juin 2022

cant seem to change my url to tally with my lavarel app

So what I am trying in my mac hosts file is:

127.0.0.1 firstproject.test

But when I run the local server and hit firstproject.test nothing happens. I was expecting that URL to resolve to 127.0.0.1?

using php artisan serve



via Chebli Mohamed