All Projects → spatie → Laravel Resource Links

spatie / Laravel Resource Links

Licence: mit
Add links to Laravel API resources

Projects that are alternatives of or similar to Laravel Resource Links

Laravel Hateoas
Expose the authorization logic of your REST API using HATEOAS links
Stars: ✭ 116 (-51.67%)
Mutual labels:  laravel, resources
Resources I Like
📚💯 Collection of learning resources i like
Stars: ✭ 280 (+16.67%)
Mutual labels:  laravel, resources
Tracker
Laravel Stats Tracker
Stars: ✭ 2,638 (+999.17%)
Mutual labels:  laravel
Laravel Twbs4
Laravel 5 frontend preset for Twitter Bootstrap 4
Stars: ✭ 237 (-1.25%)
Mutual labels:  laravel
Laravelcs
Laravel PHP_CodeSniffer
Stars: ✭ 232 (-3.33%)
Mutual labels:  laravel
Laravel Query Monitor
Simple artisan command to monitoring triggered queries
Stars: ✭ 230 (-4.17%)
Mutual labels:  laravel
Laravel Comments
Add comments to your Laravel application
Stars: ✭ 234 (-2.5%)
Mutual labels:  laravel
Tomatoidc
TomatoIDC是一款以MIT协议开源主机销售系统,具备易于扩展的插件系统,模版系统,使用强大的Laravel框架进行驱动,能帮助你轻松的扩展主机销售业务。
Stars: ✭ 230 (-4.17%)
Mutual labels:  laravel
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (-0.83%)
Mutual labels:  laravel
Lang.js
🎭 Laravel Translator class in JavaScript!
Stars: ✭ 232 (-3.33%)
Mutual labels:  laravel
Resources
📖 Huge curated collection (archive) of links of Tech, Science, Economics, Politics, Life, Philosophy, Conferences, Videos and much more resources from everyday surfing. ⭐️ Since October 21, 2017.
Stars: ✭ 236 (-1.67%)
Mutual labels:  resources
Laravel Gentelella
A Laravel 5.4 application with Gentelella bootstrap admin tempalte
Stars: ✭ 232 (-3.33%)
Mutual labels:  laravel
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (-4.17%)
Mutual labels:  laravel
Laravel Adminlte
Easy AdminLTE integration with Laravel
Stars: ✭ 2,990 (+1145.83%)
Mutual labels:  laravel
Laravel Auth
Laravel 8 with user authentication, registration with email confirmation, social media authentication, password recovery, and captcha protection. Uses offical [Bootstrap 4](http://getbootstrap.com). This also makes full use of Controllers for the routes, templates for the views, and makes use of middleware for routing. The project can be stood u…
Stars: ✭ 2,692 (+1021.67%)
Mutual labels:  laravel
Gistlog
GistLog - simple, easy blogging based on GitHub gists
Stars: ✭ 237 (-1.25%)
Mutual labels:  laravel
Awesome Recruitment
List of my favourite recruitment things 💫
Stars: ✭ 226 (-5.83%)
Mutual labels:  resources
Laravel Cronless Schedule
Run the Laravel scheduler without relying on cron
Stars: ✭ 231 (-3.75%)
Mutual labels:  laravel
Forum
Ama Laravel? Torne se um Jedi e Ajude outros Padawans
Stars: ✭ 233 (-2.92%)
Mutual labels:  laravel
Laracrud
Laravel Code Generator based on MySQL Database
Stars: ✭ 238 (-0.83%)
Mutual labels:  laravel

Add links to Laravel API resources

Latest Version on Packagist GitHub Workflow Status Check & fix styling Total Downloads

Let's say you have a UsersController with index, show, create, edit, store, update and delete methods and an UserResource. Wouldn't it be nice if you had the URL's to these methods immediately in your UserResource without having to construct them from scratch?

This package will add these links to your resource based upon a controller or actions you define. Let's look at an example of a resource.

class UserResource extends JsonResource
{
    use Spatie\ResourceLinks\HasLinks;
    use Spatie\ResourceLinks\HasMeta;

    public function toArray($request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'links' => $this->links(UsersController::class),
        ];
    }

    public static function meta()
    {
        return [
            'links' => self::collectionLinks(UsersController::class),
        ];
    }
}

Now when creating a UserResource collection, you will have all the links from the UserController available:

{
   "data":[
      {
         "id":1,
         "name": "Ruben Van Assche",
         "links": {
            "show": "https://laravel.app/users/1",
            "edit": "https://laravel.app/users/1/edit",
            "update": "https://laravel.app/users/1",
            "delete": "https://laravel.app/users/1"
         }
      }
   ],
   "meta": {
      "links": {
         "index": "https://laravel.app/users",
         "create": "https://laravel.app/users/create",
         "store":  "https://laravel.app/users"
      }
   }
}

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Why include links in your resources?

Let's say you're building a single-page application or an application built with Inertia, then you have a PHP application running at the backend and a Javascript application at the front. These applications communicate with each other via an api but what if the frontend wants to route a user to another page?

Since routes are defined in the backend, the frontend has no idea where it has to route the user to. We could just write the url's in the javascript code but what if a route is changed? So why not pass these routes from the backend to the frontend? You could just manually write down all these routes, or let this package do that job for you.

Setting up resource links

We have a dedicated docs site for this package.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].