PHP code example of victoryoalli / laravel-code-generator
1. Go to this page and download the library: Download victoryoalli/laravel-code-generator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
victoryoalli / laravel-code-generator example snippets
php artisan code:generate 'App\Models\User' -t 'schema' //prints to command line
php artisan code:generate 'App\Models\User' -t 'schema' -o 'user-schema.json'
return [
/**
* Extension files that can be used with this Blade template engine.
* You can add more if you need to.
* .blade.php
* .blade.js
* .blade.jsx
* .blade.vue
* .blade.html
* .blade.txt
* .blade.json
*/
'extensions' => [
'js',
'jsx',
'vue',
'html',
'txt',
'json',
]
];
{!!code()->PHPSOL()!!}
namespace App\Http\Controllers\API;
use App\{{$model->name}};
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class {{$model->name}}Controller extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return {{$model->name}}::all();
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
@foreach($model->table->columns as $col)
@if(!str($col->name)->matches('/_at$/') && !str($col->name)->matches('/^id$/'))
@if(!$col->nullable) '{{$col->name}}' => '
namespace App\Http\Controllers\API;
use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return User::all();
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => '