{"id":15044017,"url":"https://github.com/mahmoud-italy/larafast-fastapi","last_synced_at":"2025-04-12T17:46:03.605Z","repository":{"id":50921315,"uuid":"279600285","full_name":"Mahmoud-Italy/Larafast-fastApi","owner":"Mahmoud-Italy","description":"A Fast Laravel package to help you generate CRUD API Controllers and Resources, Model.. etc","archived":false,"fork":false,"pushed_at":"2025-04-03T16:07:12.000Z","size":342,"stargazers_count":121,"open_issues_count":3,"forks_count":16,"subscribers_count":6,"default_branch":"2.x","last_synced_at":"2025-04-03T17:23:53.490Z","etag":null,"topics":["api-generator","fastapi","generate","generate-api","larafast","laravel","lumen","scaffold"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mahmoud-Italy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Mahmoud-Italy"]}},"created_at":"2020-07-14T13:58:59.000Z","updated_at":"2025-04-03T16:07:16.000Z","dependencies_parsed_at":"2025-03-03T04:10:30.955Z","dependency_job_id":"42bd2246-dbe9-4973-9017-9b3f37935b3a","html_url":"https://github.com/Mahmoud-Italy/Larafast-fastApi","commit_stats":{"total_commits":71,"total_committers":4,"mean_commits":17.75,"dds":"0.15492957746478875","last_synced_commit":"9f13d52218935bfd34b87c0569a5f741c7ff67e3"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahmoud-Italy%2FLarafast-fastApi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahmoud-Italy%2FLarafast-fastApi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahmoud-Italy%2FLarafast-fastApi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mahmoud-Italy%2FLarafast-fastApi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mahmoud-Italy","download_url":"https://codeload.github.com/Mahmoud-Italy/Larafast-fastApi/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248609616,"owners_count":21132916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-generator","fastapi","generate","generate-api","larafast","laravel","lumen","scaffold"],"created_at":"2024-09-24T20:49:57.666Z","updated_at":"2025-04-12T17:46:03.584Z","avatar_url":"https://github.com/Mahmoud-Italy.png","language":"PHP","funding_links":["https://github.com/sponsors/Mahmoud-Italy"],"categories":[],"sub_categories":[],"readme":"# Larafast FastAPI\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Mahmoud-Italy/Larafast-fastApi/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Mahmoud-Italy/Larafast-fastApi/?branch=master)\n[![Build Status](https://scrutinizer-ci.com/g/Mahmoud-Italy/Larafast-fastApi/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Mahmoud-Italy/Larafast-fastApi/build-status/master)\n[![Code Intelligence Status](https://scrutinizer-ci.com/g/Mahmoud-Italy/Larafast-fastApi/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)\n\u003ca href=\"https://packagist.org/packages/larafast/fastapi\"\u003e\u003cimg src=\"https://poser.pugx.org/larafast/fastapi/d/total.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n![fast-api](assets/background.jpg)\n    \n   \n# What does mean FastAPI: \nA Fastapi Laravel package to help you generate CRUD API Controllers and Resources, Model.. etc\n      \n# What actually do?\nSuppose you are building an api, and you want to create controller and resources and model and factory.. etc, then you have to do a ton of other tedious and to be honest, boring things like creating migrations, model factories, the controller, form validation and adding all.\n      \nSo what FastAPI does is when you tell it the model name, it will do all those boring things. When it's done you have the following:\n\u003cul\u003e\n    \u003cli\u003eBlog.php\u003c/li\u003e\n    \u003cli\u003eBlogController.php ship with code already exists\u003c/li\u003e\n    \u003cli\u003eBlogStoreRequest.php and BlogUpdateRequest.php\u003c/li\u003e\n    \u003cli\u003eBlogResource.php\u003c/li\u003e\n    \u003cli\u003eTimestamped create_blogs_table.php migration file\u003c/li\u003e\n    \u003cli\u003eBlogFactory.php\u003c/li\u003e\n\u003c/ul\u003e\n\n# Installation\n\u003cpre\u003ecomposer require larafast/fastapi\u003c/pre\u003e\n\n# Then publish the config\n\u003cpre\u003ephp artisan vendor:publish --tag=fastApi\u003c/pre\u003e\n\n# For Lumen\nJust Add this line into bootstrap/app.php\n\u003cpre\u003e$app-\u003eregister(Larafast\\Fastapi\\FastapiServiceProvider::class);\u003c/pre\u003e\n\n# Example\n\u003cpre\u003ephp artisan fastApi Blog\u003c/pre\u003e\nOnce done, it will show you the details of the files generated.\n\n\u003cpre\u003e\nFactory created successfully\n\nCreated Migration: 2020_07_14_125128_create_blogs_table\n\nModel created successfully\n\nController created successfully\n\nRequest created successfully\n\nRequest created successfully\n\nResource created successfully\n\u003c/pre\u003e\n\n# Snapshot of BlogController\n\u003cpre\u003e\nnamespace App\\Http\\Controllers;\n\nuse App\\Blog;\nuse Illuminate\\Http\\Request;\nuse App\\Http\\Requests\\BlogUpdateRequest;\nuse App\\Http\\Requests\\BlogStoreRequest;\nuse App\\Http\\Resources\\BlogResource;\n\nclass BlogController extends Controller\n{\n    function __construct()\n    {\n        // $this-\u003emiddleware('permission:view_blogs', ['only' =\u003e ['index', 'show']]);\n        // $this-\u003emiddleware('permission:add_blogs',  ['only' =\u003e ['store']]);\n        // $this-\u003emiddleware('permission:edit_blogs', ['only' =\u003e ['update']]);\n        // $this-\u003emiddleware('permission:delete_blogs', ['only' =\u003e ['destroy']]);\n    }\n\n    public function index()\n    {\n        $rows = BlogResource::collection(Blog::filter());\n        return response()-\u003ejson([\n            'rows'        =\u003e $rows,\n            'paginate'    =\u003e $this-\u003epaginate($rows)\n        ], 200);\n    }\n\n    public function store(BlogStoreRequest $request)\n    {\n        $row = Blog::createOrUpdate(NULL, request()-\u003eall());\n        if($row === true) {\n            return response()-\u003ejson(['message' =\u003e ''], 201);\n        } else {\n            return response()-\u003ejson(['message' =\u003e 'Unable to create entry ' . $row], 500);\n        }\n    }\n\n    public function show($id)\n    {\n        $row = new BlogResource(Blog::findOrFail(decrypt($id)));\n        return response()-\u003ejson(['row' =\u003e $row], 200);\n    }\n\n    public function update(BlogUpdateRequest $request, $id)\n    {\n        $row = Blog::createOrUpdate(decrypt($id), request()-\u003eall());\n        if($row === true) {\n            return response()-\u003ejson(['message' =\u003e ''], 200);\n        } else {\n            return response()-\u003ejson(['message' =\u003e 'Unable to update entry ' . $row], 500);\n        }\n    }\n\n    public function destroy($id)\n    {\n        try {\n            $row = Blog::query();\n           \n            // can work with multi select\n            if(strpos($id, ',') !== false) {\n                foreach(explode(',',$id) as $sid) {\n                    $ids[] = $sid;\n                }\n                $row-\u003ewhereIN('id', $ids);\n            } else {\n                $row-\u003ewhere('id', $id);\n            }   \n            $row-\u003edelete();\n\n            return response()-\u003ejson(['message' =\u003e ''], 200);\n        } catch (\\Exception $e) {\n            return response()-\u003ejson(['message' =\u003e 'Unable to delete entry, '. $e-\u003egetMessage()], 500);\n        }\n    }\n}\n\n\u003c/pre\u003e\n\n# Snapshot of Blog Model\n\u003cpre\u003e\nnamespace App;\n\nuse DB;\nuse App\\Image;\nuse Illuminate\\Pipeline\\Pipeline;\nuse Larafast\\Fastapi\\QueryFilters\\Sort;\nuse Larafast\\Fastapi\\QueryFilters\\Locale;\nuse Larafast\\Fastapi\\QueryFilters\\Search;\nuse Illuminate\\Support\\Str;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Blog extends Model\n{\n    protected $guarded = [];\n\n    // imageable polymorphic\n    public function image() {\n        return $this-\u003emorphOne(Image::class, 'imageable');\n    }\n    \n    // Filter\n    public static function filter()\n    {\n        return app(Pipeline::class)\n                -\u003esend(self::query())\n                -\u003ethrough(\n                [\n                    Locale::class,\n                    Search::class,\n                    Sort::class\n                ])\n                -\u003ethenReturn()\n                -\u003epaginate(request('paginate') ?? 10);\n    }\n    \n\n    // Create or Update\n    public static function createOrUpdate($id, $value)\n    {\n        try {\n\n            // Begin Transaction\n            DB::beginTransaction();\n\n                // find Or New\n                $row              = (isset($id)) ? self::find($id) : new self;\n                $row-\u003etitle       = $value['title'] ?? NULL;\n                $row-\u003ebody        = $value['body'] ?? NULL;\n                $row-\u003esave();\n\n                // Image\n                if(isset($value['image'])) {\n                    $row-\u003eimage()-\u003edelete();\n                    if($value['image']) {\n                        if(!Str::contains($value['image'], [ Imageable::contains() ])) {\n                            $image = Image::uploadImage($value['image']);\n                        } else {\n                            $image = explode('/', $value['image']);\n                            $image = end($image);\n                        }\n                        $row-\u003eimage()-\u003ecreate([ 'url' =\u003e $image ]);\n                    }\n                }\n\n\n            DB::commit();\n            // End Commit of Transaction\n\n            return true;\n        } catch (\\Exception $e) {\n            DB::rollback();\n            return $e-\u003egetMessage();\n        }\n    }\n}\n\n\u003c/pre\u003e\n\n\n\n\n# Snapshot of Blog Resource\n\u003cpre\u003e\nnamespace App\\Http\\Resources;\n\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\n\nclass BlogResource extends JsonResource\n{\n\n    public function toArray($request)\n    {\n        return [\n            'id'            =\u003e $this-\u003eid,\n            'encrypt_id'    =\u003e encrypt($this-\u003eid),\n            'image'         =\u003e ($this-\u003eimage) ? $this-\u003eimage-\u003eurl : NULL,\n\n            'title'         =\u003e $this-\u003etitle,\n            'body'          =\u003e $this-\u003ebody,\n\n            'dateForHumans' =\u003e $this-\u003ecreated_at-\u003ediffForHumans(),\n            'timestamp'     =\u003e $this-\u003ecreated_at\n        ];\n    }\n}\n\u003c/pre\u003e\n\n\n\nNow add the necessary fields and run\n\n\u003cpre\u003ephp artisan migrate\u003c/pre\u003e\nAnd that saved you an hour worth of repetitive and boring work which you can spend on more important development challenges.\n\n# Credits\n\n  \u003cul\u003e\n    \u003cli\u003e\u003ca href=\"https://github.com/Mahmoud-Italy\"\u003eMahmoud Italy\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"https://github.com/Mahmoud-Italy/Larafast-fastApi/graphs/contributors\"\u003eAll Contributors\u003c/a\u003e\u003c/li\u003e\n  \u003c/ul\u003e\n  \n# License\nThe MIT License (MIT). Please see License File for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahmoud-italy%2Flarafast-fastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmahmoud-italy%2Flarafast-fastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahmoud-italy%2Flarafast-fastapi/lists"}