Questions tagged [laravel-7]

Laravel 7 is the previous stable version of the open-source PHP web framework created by Taylor Otwell. It was released on March 3, 2020. Please use the [laravel] tag for general Laravel-related questions.

Laravel 7 continues the improvements made in Laravel 6.x by introducing Laravel Sanctum, routing speed improvements, custom Eloquent casts, Blade component tags, fluent string operations, a developer-focused HTTP client, first-party CORS support, improved scoping for route model binding, stub customization, database queue improvements, multiple mail drivers, query-time casts, a new artisan test command, and a variety of other bug fixes and usability improvements.


New features overview:

  • Laravel Airlock

Laravel Airlock provides a featherweight authentication system for SPAs (single-page applications), mobile applications, and simple, token-based APIs. Airlock allows each user of your application to generate multiple API tokens for their account. In addition, these tokens may be granted abilities/scopes which specify which actions the tokens are allowed to perform.

  • Custom Eloquent Casts

Laravel has various built-in, helpful cast types; however, you may occasionally need to define your cast types. You may now accomplish this by defining a class that implements the CastsAttributes interface.

Classes that implement this interface must define get and set methods. The get method is responsible for transforming a raw value from the database into a cast value, while the set method should transform a cast value into a raw value that can be stored in the database.

  • Blade Component Tags & Improvements

Blade components have been overhauled for tag-based rendering, attribute management, component classes, and inline view components. Since the overhaul of Blade components is so extensive, please consult the complete Blade component documentation to learn about this feature.

  • HTTP Client

Laravel now provides an expressive, minimal API around the Guzzle HTTP client, allowing you to quickly make outgoing HTTP requests to communicate with other web applications. Laravel’s wrapper around Guzzle is focused on its most common use cases and an excellent developer experience.

  • Route Caching Speed Improvements

Laravel 7 includes a new method of matching compiled, cached routes that have been cached using the route:cache Artisan command. On large applications (for example, applications with 800 or more routes), these improvements can result in a 2x speed improvement in requests per second on a simple “Hello World” benchmark. Again, no changes to your application are required.

2270 questions
8
votes
1 answer

Laravel Sanctum : blocked by CORS policy with Nuxt Auth module

I have a Laravel website served by Valet on backend.test and a Nuxt SPA on nuxt.backend.test:3005. When I try to authenticate to Sanctum with Nuxt Auth module, I get the CORS error below: Access to XMLHttpRequest at 'http://backend.test/login' from…
DevonDahon
  • 7,460
  • 6
  • 69
  • 114
8
votes
3 answers

Why does Cache::lock() return false in Laravel 7?

My framework is Laravel 7 and the Cache driver is Memcached. I want to perform atomic cache get/edit/put. For that I use Cache::lock() but it doesn't seem to work. The $lock->get() returns false (see below). How can I resolve this? Fort testing, I…
horse
  • 707
  • 4
  • 11
  • 30
8
votes
2 answers

Laravel Eloquent API Resources: remove "data" key from response (collection)

I've Eloquent API Resource UserResource. When I try run something like this code: $users = User::paginate(10); return UserResource::collection($users); Response will be like this: { "data": [ { "name": "Fatima Conroy", …
Andreas Hunter
  • 4,504
  • 11
  • 65
  • 125
7
votes
2 answers

The request response was returned in $kernel->handle($request)

this is code from laravel API public/index.php file. $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request,…
Takhtak Team
  • 131
  • 1
  • 2
  • 10
7
votes
4 answers

Laravel 7: Why isn't my session cookie getting set in a browser?

My Laravel session cookie doesn't get set in a browser even though the server response contains the right Set-Cookie header. The Laravel server is running at localhost:8000, and the client application is a NuxtJS SPA running at localhost:7000. The…
ChristianF
  • 1,735
  • 4
  • 28
  • 56
7
votes
4 answers

Laravel PHPUnit returning 404

For laravel API I have write the test cases. But whenever I am running the test cases it always failed with below error, 1) Tests\Feature\CompanyTest::orgTest Expected status code 200 but received 404. Failed asserting that 200 is identical to…
Narayan
  • 1,670
  • 1
  • 19
  • 37
7
votes
3 answers

Did I solve my "Target class [mail.manager] does not exist." issue?

Just upgraded from Laravel 6 to 7, and had the error response above when submitting a contact form. I eventually found a solution that seems to work and I am submitting here to help out the next guy. In the terminal run: composer require…
noviguy
  • 73
  • 1
  • 4
7
votes
6 answers

Laravel Echo is not listening

I set up an event and new channel : class TaskCreated implements shouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; public $task; public function __construct(Task $task) { $this->task = $task; } } and installed Echo…
AlmoDev
  • 969
  • 2
  • 18
  • 46
7
votes
6 answers

Render Laravel 7 component programmatically

I have a Laravel 7 component which looks like this class Input extends Component { public $name; public $title; public $value; public $type = 'text'; /** * Create a new component instance. * * @return void …
Dan
  • 115
  • 1
  • 8
7
votes
2 answers

What is the difference between a JsonResource & ResourceCollection? in Laravel v6 or v7

Can someone explain the difference between a ResourceCollection and JsonResource? In Laravel 6 docs you can generate 2 different types of resources... ResourceCollection and JsonResource.…
Bel
  • 75
  • 1
  • 9
7
votes
3 answers

Laravel 7 email exceptions broke after Symfony 5 update

I've upgraded to Laravel 7.1 and now with Symfony 5 these classes no longer exist: use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler; I used them in my…
climbd
  • 405
  • 1
  • 5
  • 11
6
votes
6 answers

How to setup laravel file permission once and for all

I have followed this upvoted answer and did the following: sudo chown -R my-user:www-data /var/www/domain.com/ sudo find /var/www/domain.com/ -type f -exec chmod 664 {} \; sudo find /var/www/domain.com/ -type d -exec chmod 775 {} \; sudo chgrp -R…
jewishmoses
  • 1,069
  • 2
  • 11
  • 16
6
votes
1 answer

I need to load my data from database to my e-commerce index page. Admin part is perfectly fine. But I got errors in my users

I have created two resource controllers, one for admin and another one for users. I got the error as, Illuminate\Contracts\Container\BindingResolutionException Target class [App\Http\Controllers\ProductsController] does not exist. What is the…
Zeenath
  • 329
  • 1
  • 5
  • 22
6
votes
2 answers

Alias to call model class in artisan tinker

This question might sound silly, but I really wish to know if there is a way to solve the problem of long model path in artisan commands. I have a models organized in the following structure: `app\Models\Auth\User.php` And in the User model, I…
Lamar
  • 1,761
  • 4
  • 24
  • 50
6
votes
0 answers

Authentication problem in SSR mode Nuxt on laravel sanctum

Setup is based on Laranuxt - Combination of Laravel 7 and Nuxt. Running on Windows with PHP 7.4.8 Ive been trying to authenticate a user on a nuxt application through Laravel 7 with Sanctum authenticator module. I now get a response that that seems…
Stian Blåsberg
  • 115
  • 2
  • 8