mteb/FreshStackRetrieval huggingface dataset:
I have tried several tutorials in the internet but it doesn't work or the language not changing, I already stored the translation into \lang directory, and the session is already set Localization Session
here is my source code:
This is my controller :
class LocalizationController extends Controller
{
    public function setLang($locale)
    {
        App::setLocale($locale);
        Session::put("locale", $locale);

        return redirect()->back();
    }
}

This is my Middleware :
class LocalizationMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if (Session::get("locale") != null) {
            App::setLocale(Session::get("locale"));
        } else {
            Session::put("locale", "en");
            App::setLocale(Session::get("locale"));
        }

        return $next($request);
    }
}

This is the route :
Route::get("locale/{lang}", [LocalizationController::class, 'setLang']);

Language Switcher :
<a href="{{ url('locale/id') }}"><img class="h-5 mt-4" src="{{ asset('images/flag/id_flag.png') }}"
                alt=""></a>
        <a href="{{ url('locale/en') }}"><img class="h-5 mt-4" src="{{ asset('images/flag/uk_flag.png') }}"
                alt=""></a>

Translated Element :
<h1 class="font-black lg:text-5xl md:text-4xl text-3xl md:w-[500px] mx-auto">{{ __('home.hero.header') }}</h1>

I have tried several tutorials in the internet, please help.
I'm writing a feature test and noticed that the session ID value changes after every request.
For instance, each dumped value will be different:
dump(session()->getId());

$response = $this->get('/?param=foo');

dump(session()->getId());

$response = $this->get('/?param=foo');

dump(session()->getId());

This issue doesn't seem to happen outside of the testing environment. I can reload a page in the browser and the session ID remains consistent.
This is my web middleware group, which is pretty standard out of the box:
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,

I'm running this Laravel app on Valet on Mac with zero custom PHP configuration changes. Just whatever Homebrew provides with php@8.1.
Here are the session values from php -i:
session.auto_start => Off => Off
session.cache_expire => 180 => 180
session.cache_limiter => nocache => nocache
session.cookie_domain => no value => no value
session.cookie_httponly => no value => no value
session.cookie_lifetime => 0 => 0
session.cookie_path => / => /
session.cookie_samesite => no value => no value
session.cookie_secure => 0 => 0
session.gc_divisor => 1000 => 1000
session.gc_maxlifetime => 1440 => 1440
session.gc_probability => 1 => 1
session.lazy_write => On => On
session.name => PHPSESSID => PHPSESSID
session.referer_check => no value => no value
session.save_handler => files => files
session.save_path => no value => no value
session.serialize_handler => php => php
session.sid_bits_per_character => 5 => 5
session.sid_length => 26 => 26
session.upload_progress.cleanup => On => On
session.upload_progress.enabled => On => On
session.upload_progress.freq => 1% => 1%
session.upload_progress.min_freq => 1 => 1
session.upload_progress.name => PHP_SESSION_UPLOAD_PROGRESS => PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix => upload_progress_ => upload_progress_
session.use_cookies => 1 => 1
session.use_only_cookies => 1 => 1
session.use_strict_mode => 0 => 0
session.use_trans_sid => 0 => 0
session.trans_sid_hosts => no value => no value
session.trans_sid_tags => a=href,area=href,frame=src,form= => a=href,area=href,frame=src,form=

In my phpunit.xml file:
<server name="SESSION_DRIVER" value="array"/>

What could cause the session to be regenerated every time?
I am upgrading a Laravel 5.2 site to 10.20.
I followed the official documentation to encrypt/decryt the data the Laravel 10.x way as it was done differently on 5.2 (see it used the trait Encryptable).
When retrieving encrypted data from the same database (with the same APP_KEY) in Laravel 5.2 I get Hello World whereas on 10.20 I get s:11:"Hello World".
The other attributes that are not encrypted are shown correctly.
I searched the web for that but did not found anything pertaining to that issue. ChatGPT told me it was linked to serialization but even with that keyword I did not find the problem described somewhere.
In my model the attributes to be encrypted are cast like this :
        protected $casts = [
        'my_not_encrypted_attribute' => 'boolean',
        'my_encrypted_attribute_string' => 'encrypted'        
    ];



Can you tell me how to get rid of that prefix and only get the actual payload as in L5.2 ?
Thanks for your help!
EDIT :
Manually defining the accessors in my model requires the use of unserialize() to get clean data :
    protected function myEncryptedAttributeString(): Attribute
    {
        return Attribute::make(
            get: fn (string $value) => unserialize(Crypt::decryptString($value)),
        );
    }

So it would mean that the data stored in the database were serialized before being stored.That's weird because the Encryptable trait shows no trace of  serialize in the setters :
public function setAttribute($key, $value) {
        if (in_array($key, MyModel::getEncryptableAttributes())) {
            $value = Crypt::encrypt($value);
        }

        return parent::setAttribute($key, $value);
    }

Nor can I find trace of unserialize in the getters (although for the same database the output was clean) :
public function getAttribute($key) {
        $value = parent::getAttribute($key);
        //[...]
        $decrypted = Crypt::decrypt($value);
        //[...]
        return $decrypted;
}
When I retrieve data directly from the model using the following approach:
Contact::where('company_id', auth()->user()->company_id)->get()

The query looks like this:
select * from "contacts" where "company_id" = 'xxx'

But when I retrieve data through direct relations like this:
auth()->user()->company->contacts

The query looks like this and takes longer:
select * from "contacts" where "contacts"."company_id" = 'xxx' and "contacts"."company_id" is not null

It adds the additional;
and "contacts"."company_id" is not null

part, which affects performance negatively. What should I do to prevent this? Querying directly from models without using relations anywhere also doesn't seem very logical and clean.
Note: company_id is indexed.
i am developing a web app with laravel 10 with Livewire 3, trying to scripting for SPA (Single Page Application), problem is when i click "account" button its load the blank page with current year as a text "2023" instead of accoount.blade.php content.
this is what i have tried:
from Livewire/App.php:
<?php

namespace App\Livewire;

use Livewire\Component;

class Main extends Component
{
    public function render()
    {
        return view('app');
    }
}

from resources\views\livewire\app.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    @livewireStyles
</head>
<body>
    <main class="content-wrapper">

        @include('header')

        <div class="container-xxl flex-grow-1 container-p-y">

            @yield('content')

        </div>

    </main>
    @livewireScripts
</body>
</html>

from resources\views\header.blade.php:
<nav class="navbar navbar-expand-lg bg-light">
    <div class="container-fluid">
      <a class="navbar-brand" href="#">Navbar</a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav me-auto mb-2 mb-lg-0">
          <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="#">Home</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/account" wire:navigate>Account</a>
          </li>
        </ul>
      </div>
    </div>
</nav>

from Livewire/Account.php:
<?php

namespace App\Livewire;

use Livewire\Component;

class Account extends Component
{
    public function render()
    {
        return view('livewire.account')
            ->extends('app')
            ->section('content');
    }
    
}

from resources\views\livewire\account.blade.php:
<div>
    Account Page
</div>

the result is once page loads:

What wrong i have done here?
Let's say I have an uploads.index.view.php and an uploads.show.view.php, which lead to the UploadController, which is a resource controller.
The index view shows a list of user-uploaded files as such:
Upload controller:
public function index() {
    return view('home', [
        'uploads' => Upload::paginate(20)
    ]);
}

Index view:
@foreach ($uploads as $upload)
<tr>
    <td class="table-uploaded table-td--center"><a href="#">{{$upload->user->name}}</a></td>
    <td class="table-cat table-td--center">{{$upload->category->category}}</td>
    @if ($upload->name)
    <td class="table-title"><a href="{{route('uploads.show', $upload->id)}}">{{$upload->name}}</a></td>
    @else
    <td class="table-title"><a href="{{route('uploads.show', $upload->id)}}">{{$upload->title}}</a></td>
    @endif
</tr>
@endforeach

And the show view shows a single upload's page as such:
public function show(Upload $upload) {
    return view('single', [
        'upload' => $upload
    ]);
}

The index should contain a <a href="DOWNLOAD LINK HERE">UPLOAD TITLE</a> and the single view contains a <a href="DOWNLOAD LINK HERE">Download</a>.
What's the most Eloquent way to have the browser download the corresponding $upload upon clicking any of the two links? Am I making a function inside of the index and show public functions in the UploadController, or a separate public function download() for the UploadController?
Would appreciate a detailed answer, including what to put in the <a></a> tags and the route, since I'm fairly new to this.
I am attempting to install my Laravel 10 project in a subfolder so that I can access it at example.com/laravel-project/ instead of example.com/laravel-project/public/. Here is the .htaccess configuration I tried in the /laravel-project/ directory:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/ [L]
</IfModule>

This configuration results in a Laravel-styled 404 error when accessing the subfolder URL. I've reviewed other questions and it seems that something has changed in Laravel 10 that prevents this setup from working as it did in previous versions. I'd like to avoid using php artisan serve. Additionally, I have the following set in my .env file, which should also be correct:
#...
APP_DIR=laravel-project
APP_URL=http://example.com/laravel-project
#...

How can I configure the .htaccess file or Laravel 10 setup to correctly render the homepage at the subfolder URL without having to go to public/ in the URL?
Edit: The site will be on shared hosting
I am creating a migration in Laravel and I need to reference the same table 2 times. I explain:
The "inventory" table has the "responsible" and "created by" fields that refer to the user table. The person responsible and the creator may be the same person in certain cases.
This is the migration code:
Schema::create('inventory', function (Blueprint $table) {
            $table->id();
            $table->integer('type');
            $table->string('state', 50);
            $table->timestamps();
            $table->foreignId('user_id')->constrained(
                table: 'user',
                indexName: 'created_inventory_id'
            )->cascadeOnUpdate()->restrictOnDelete();
            $table->foreignId('user_id')->constrained(
                table: 'user',
                indexName: 'responsible_inventory_id'
            )->cascadeOnUpdate()->restrictOnDelete();
            $table->foreignId('area_id')->constrained(
                table: 'area',
                indexName: 'area_inventory_id'
            )->cascadeOnUpdate()->restrictOnDelete();
        });

When I run the migration it gives me the following error:
SQLSTATE[42701]: Duplicate column: 7 ERROR:  column "user_id" was specified more than once (Connection: pgsql, SQL: create table "inventory"

How could I resolve that?
I can not get object data to pass to Blade template with Mccarlosen/Laravel-mpdf Package. The desire is to pass a singe row database record but call to page is met with error - "undefined variable $agency"
Target blade data syntax is correct as follows -
{{ $agency->id }}

Instructions per the repo as follows -
    use PDF;

class ReportController extends Controller 
{
    public function viewPdf()
    {
        $data = [
            'foo' => 'bar'
        ];

        $pdf = PDF::loadView('pdf.document', $data);

        return $pdf->stream('document.pdf');
    }

}

In my controller, I am calling the Object without failure, grabbing the data without failure, and streaming pdf correctly without data (all tested). But when $agency is chained according to example above (per the common Laravel syntax) it fails. I believe this might be secondary to nested structure of data in Laravel object. But not sure. My controller function is below.
public function print(string $id) {

        // Read a single row of data in the Model
        $agency = Agency::find($id);

        // Redirect to the view with the data
        $pdf = PDF::loadView('modules.agencyMain.print',$agency);

        return $pdf->stream('agency.pdf');

    }

Looking for guidance/answers.
I want to save image file in the storage folder but when I insert a file in my form and I click on the button, it displays me the error "Path cannot be empty".
Path cannot be empty
{"exception":"[object] (RuntimeException(code: 0): Path cannot be empty at C:\\laragon\\www\\nextdrive_web\\vendor\\nyholm\\psr7\\src\\Factory\\Psr17Factory.php:41)
[stacktrace]
#0 C:\\laragon\\www\\nextdrive_web\\vendor\\symfony\\psr-http-message-bridge\\Factory\\PsrHttpFactory.php(118): Nyholm\\Psr7\\Factory\\Psr17Factory->createStreamFromFile('')
#1 C:\\laragon\\www\\nextdrive_web\\vendor\\symfony\\psr-http-message-bridge\\Factory\\PsrHttpFactory.php(100): Symfony\\Bridge\\PsrHttpMessage\\Factory\\PsrHttpFactory->createUploadedFile(Object(Symfony\\Component\\HttpFoundation\\File\\UploadedFile))
#2 C:\\laragon\\www\\nextdrive_web\\vendor\\symfony\\psr-http-message-bridge\\Factory\\PsrHttpFactory.php(72): Symfony\\Bridge\\PsrHttpMessage\\Factory\\PsrHttpFactory->getFiles(Array)
#3 C:\\laragon\\www\\nextdrive_web\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RoutingServiceProvider.php(139): Symfony\\Bridge\\PsrHttpMessage\\Factory\\PsrHttpFactory->createRequest(Object(Illuminate\\Http\\Request))
#4 C:\\laragon\\www\\nextdrive_web\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(873): Illuminate\\Routing\\RoutingServiceProvider->Illuminate\\Routing\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#5 C:\\laragon\\www\\nextdrive_web\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(758): Illuminate\\Container\\Container->build(Object(Closure))
I'm using Laravel 10 and Laravel Passport and in this project, I tried registering new users like this:
public function register(Request $request)
    {
        $request->validate([
            'name' => 'required|max:255',
            'email' => 'required|unique:users|max:255',
            'password' => 'required|min:6'
        ]);

        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password)
        ]);

        $token = $user->createToken('MyApp')->accessToken;

        return response([
            'token' => $token
        ]);
    }

Then I defined another route which is under api middleware:
Route::post('register',[AuthenticationController::class,'register']);

Route::middleware('auth:api')->group(function() {
    Route::resource('products', ProductController::class);
});

And in the ProductController I tried adding this method for storing new products:
public function store(Request $request)
    {
        $request->validate([
            'title' => 'required|max:255',
            'description' => 'required|max:255',
            'price' => 'required'
        ]);

        if ($request->user()) {
            Product::create([
                'title' => $request->title,
                'description' => $request->description,
                'price' => $request->price,
                'user_id' => $request->user()->id
            ]);

            return response([
                'message' => 'product created successfully'
            ],201);
        }else{
            return response(['message' => 'User not authenticated.'], 401);
        }
    }

But when I test the url in PostMAN which is this:
http://localhost:8000/api/products

I get this message:
{
    "message": "Unauthenticated."
}

However I have copied and pasted the token retrieved from /register rendpoint as Token input of Authorization section:

I also set the Headers to Accept and application/json and sent these form-data as Body:
title:myproduct
description:The production desc
price:2000

I don't know why I get this Unauthenticated Message, I also configured the auth.php like this:
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],

And added this Service Provider to app.php:
Laravel\Passport\PassportServiceProvider::class,

And used the correct class at User Model:
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
    ...
}

So what's going wrong here? How can I solve this issue?

UPDATE #1:
Result of dd($user->createToken('MyApp'));:
I created the laravel project and the problem is that the admin users are filling the form along jpg file and the file is being uploaded and being stored in storage directory but where the image aim to be displayed to public users it is not being displayed.
{{url('/storage/app/news/' . $val2->id . '.png') }}"

Although the file exists at that locations.
I tried with changing the file reading mode permission for server.
I have not moved to deployment phase although, the issue is in Laravel development server.
The file is not being displayed at web while file is there don't know access issue or what else.
I'm working with Laravel latest version and I want to show an image like this:
<img src="{{ asset('storage/'.$media->med_path) }}" alt="Thumbnail" style="width: 100px; height: auto;">

And when I see the source code it adds this value to src attribute of image tag:
http://localhost:8000/storage/public/medias/jpg/57N8MJmsp2y8P0aexysV_200x200.jpg
But the image itself not showing up somehow:

Here is also the value of variable ($media->med_path) in the DB:
public/medias/jpg/57N8MJmsp2y8P0aexysV_200x200.jpg

However I have already ran the command php artisan storage:link and the links are already exists via this filesystems.php config file:
'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
            'throw' => false,
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
            'throw' => false,
        ],

        ...

        'links' => [
            public_path('storage') => storage_path('app/public'),
        ],

And the image already exists in this directory of my project:
-project
     -storage
           -app
                -public
                     -medias
                          -jpg
                               -57N8MJmsp2y8P0aexysV_200x200.jpg

So what's going wrong here? How can I solve this issue and show the image properly?
I'm trying to cache my routes using php artisan route:cache and it returns a logic exception because it thinks the route name is already used, which isn't the case. Here's the exception i get:

LogicException : Unable to prepare route [registreren] for serialization. Another route has already been assigned name [auth.register].

Here's my primary web.php routing file:
Route::name('auth.')->middleware(['basket'])->group(__DIR__ . '/web/auth.php');
Route::name('client.')->middleware(['basket'])->group(__DIR__ . '/web/client.php');
Route::prefix('admin')->name('admin.')->middleware(['admin'])->group(__DIR__ . '/web/admin.php');

Here's the excerpt of the auth.php routing file which throws the exception:
Route::controller(AuthRegisterController::class)->name('register')->middleware('guest')->group(function () {
    Route::get('/registreren', 'view');
    Route::post('/registreren', 'action');
});


I've searched through the routing files if i didn't accidently used the auth.register name twice but i didn't. However when i name the routes in the register group, it works:
Route::controller(AuthRegisterController::class)->name('register.')->middleware('guest')->group(function () {
    Route::get('/registreren', 'view')->name('get');
    Route::post('/registreren', 'action')->name('post');
});

Now i'm wondering, is this expected behaviour? The routing works perfectly without naming the get and post routes:
<a href="{{ route('auth.register') }}">
<form method="post" action="{{ route('auth.register') }}">

If this is expected behaviour, then the exception description is very misleading. I am hoping there's another solution to this problem because we've used the same approach for dozens of routes not to mention the hunderds of route calls in our views. Maybe it's a bug or i am doing something else wrong because it would require a huge refactor to name all the routes and route calls. Any thoughts would be very welcome, thanks.
I have two models:

User
Place
and a Pivot as:
Role(user_id, place_id, type)
and an example of type is "["manager", "reception"]" and i want to change this value to collection when retriving as:
Place::find(1)->users[0]->pivot->type

i add this method but it doesn't work and return string:
    public function getTypeAttribute($value){
        return collect(json_decode($value));
    }
I'm currently develop a web application with Laravel.
My database engine is a Microsoft SQL Server.
For some data I preferred to generate an uuid.
When I use Windows to run my Laravel app, the uuid format is correct :

A5EE121A-1F10-46FC-B779-49D2A0FA3B68

But when I ran my Laravel app under linux, and use the same database, the uuid format is like this :

b"\x1A\x12î¥\x10\x1FüF·yIÒ ú;h"

I don't know where is the problem...
Have you an idea ?
Thanks.
The goal is to retrieve the same format when the Laravel app ran under Windows and under Linux.