-1

I get this error whent I want to login in my session, and I don't how I solve it, I so need it because tomorrow my graduation. The first error in line : $response = $kernel->handle( $request = Request::capture() )->send();


use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));


if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
   require $maintenance;
}

require __DIR__.'/../vendor/autoload.php';


$app = require_once __DIR__.'/../bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(
   $request = Request::capture()
)->send();

$kernel->terminate($request, $response);

and the 2nd error in the last line


<?php



$publicPath = getcwd();
$uri = urldecode(

    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?? ''

);
if ($uri !== '/' && file_exists($publicPath.$uri)) {

    return false;

}
require_once $publicPath.'/index.php';

And this is the authClass

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AuthController extends Controller
{
    public function getLogin()
    {
        return view('admin.auth.login');
    }
    public function postLogin(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required'
        ]);
        $validated = auth()->attempt([
            'email' => $request->email,
            'password' => $request->password,
            'is_admin' => 1
        ], $request->password);
        if ($validated) {
            return redirect()->route('dashboard')->with('success', 'Login Successfull');
        } else {
            return redirect()->back()->with('error', $request);
        }
    }
}

this line was write like this return redirect()->back()->with('error', 'Invalid Credentials'); i change to know the error only

  • The `$request` object consists of some callbacks in it so you can't pass it along in a redirection. "Passing data" in a redirect involves serialising them, storing them in the session, and then deserialising them on the next request. If you want to pass the request data over, you can consider doing `redirect()->back()->with('error', $request->all())` – apokryfos Jun 08 '23 at 07:33
  • I get this error ``` htmlspecialchars(): Argument #1 ($string) must be of type string, array given``` – Damess Fatima Zahra Jun 08 '23 at 08:28
  • Not entirely sure what you are trying to do here. Your original `return redirect()->back()->with('error', 'Invalid Credentials');` should work and will say that the authentication failed because of invalid credentials. – apokryfos Jun 08 '23 at 08:37
  • Yes, this is what is return. After delete package jetStream and livewire and Fortify, I can't login and tell me the credentials invalid but them valid.(The system is working before I add the packages and after adding I modified same things then it worked, When I deleted the packages, I couldn't login again and telle me that the credentials invalid. – Damess Fatima Zahra Jun 08 '23 at 08:48
  • Try deleting one package at a time until you can find which one causes the issues. JetStream provides a boilerplate Laravel application (so maybe keep that one). Removing jetStream specifically is pretty involved because JetStream gets integrated into your app – apokryfos Jun 08 '23 at 09:30

1 Answers1

-2

In Laravel, the serialization of closures is not allowed by default. This limitation exists because closures are anonymous functions that can contain references to the surrounding context and variables. Serializing closures with their surrounding state can be complex and error-prone.

When you attempt to serialize a closure in Laravel, you may encounter an error similar to:

Serialization of 'Closure' is not allowed

To work around this limitation, you can refactor your code to avoid serializing closures. Instead, you can use other serializable types such as classes or data structures like arrays or objects.

If you need to store some state or behavior, you can create a class and define the required methods or properties. Then, you can serialize and unserialize instances of that class without any issues.

Here's an example of refactoring code that uses a closure into a class:

class MySerializableClass
{
    public function doSomething()
    {
        // Your code here
    }
}

$serializableInstance = new MySerializableClass();

// Serialize the instance
$serialized = serialize($serializableInstance);

// Unserialize the instance
$unserialized = unserialize($serialized);

// Call the method on the unserialized instance
$unserialized->doSomething();

By using a serializable class, you can safely serialize and unserialize instances without encountering any issues related to closures.

Keep in mind that closures are a powerful feature in PHP, but they have limitations when it comes to serialization. Refactoring your code to use serializable classes can help you overcome this limitation in Laravel.

dekts
  • 744
  • 4
  • 19