PHP code example of arkadiuszbachorski / laravel-xmake
1. Go to this page and download the library: Download arkadiuszbachorski/laravel-xmake 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/ */
arkadiuszbachorski / laravel-xmake example snippets
namespace App\Http\Controllers;
use App\Foobar;
use App\Http\Requests\FoobarRequest;
class FoobarController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$foobars = Foobar::all();
return response()->json([]);
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
return response()->json([]);
}
/**
* Store a newly created resource in storage.
*
* @param FoobarRequest $request
* @return Response
*/
public function store(FoobarRequest $request)
{
Foobar::create($request->validated());
return response()->json([]);
}
/**
* Display the specified resource.
*
* @param Foobar $foobar
* @return \Illuminate\Http\Response
*/
public function show(Foobar $foobar)
{
return response()->json([]);
}
/**
* Show the form for editing the specified resource.
*
* @param Foobar $foobar
* @return \Illuminate\Http\Response
*/
public function edit(Foobar $foobar)
{
return response()->json([]);
}
/**
* Update the specified resource in storage.
*
* @param FoobarRequest $request
* @param Foobar $foobar
* @return \Illuminate\Http\Response
*/
public function update(FoobarRequest $request, Foobar $foobar)
{
$foobar->update($request->validated());
return response()->json([]);
}
/**
* Remove the specified resource from storage.
*
* @param Foobar $foobar
* @return \Illuminate\Http\Response
* @throws \Exception
*/
public function destroy(Foobar $foobar)
{
$foobar->delete();
return response()->json([]);
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
class Foobar extends Model
{
protected $guarded = [];
}
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class FoobarRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => '',
'foo' => '',
'bar' => '',
];
}
}
[
'paths' => [
// Path where stubs are expected to exist. This path affects vendors publishing too.
'stubs' => '/resources/xmake/stubs',
// Path where fields.php is expected to exist. This path affects vendors publishing too.
'fields' => '/resources/xmake',
],
'database' => [
// Flag that indicates whether ->nullable() should be automatically added if provided in validation
'addNullableIfAppearsInValidation' => true,
],
'controller' => [
// You can change PHPDoc methods captions there
'docs' => [
'index' => 'Display a listing of the resource.',
'create' => 'Show the form for creating a new resource.',
'store' => 'Store a newly created resource in storage.',
'show' => 'Display the specified resource.',
'edit' => 'Show the form for editing the specified resource.',
'update' => 'Update the specified resource in storage.',
'destroy' => 'Remove the specified resource from storage.',
],
// You can change CRUD methods names there
'methods' => [
'index' => 'index',
'create' => 'create',
'store' => 'store',
'show' => 'show',
'edit' => 'edit',
'update' => 'update',
'destroy' => 'destroy',
],
],
'seeder' => [
// Default amount used in seeders if not provided by --amount option
'defaultAmount' => 50,
],
'resource' => [
// Flag that indicates whether resource fields should be parsed to camelCase
'camelizeFields' => true,
],
'validation' => [
// It enables parsing pipe syntax (i.e. "string|nullable") to array
'parseArray' => true,
// It enables guessing validation based on database field. I.e. string('foobar') parses to 'string' validation.
'guessBasedOnDatabase' => true,
],
// You can change what will be created if you select "create everything"/"all" option
'createEverything' => [
'model' => true,
'migration' => true,
'factory' => true,
'seeder' => true,
'request' => true,
'resource' => true,
'controller' => true,
],
];
[
// key used in --fields option
'title20ch' => [
/*
Field name used in Eloquent, database migration.
I.e $model->title
*/
'name' => 'title',
/*
Used in factory after $faker->
I.e. 'title' => $faker->sentence(2)
*/
'factory' => 'sentence(2)',
'validation' => 'string|nullable',
/*
Migration, NAME will by replaced with actual name automatically
I.e. string('title', 20)->default('test'),
*/
'database' => 'string(NAME, 20)->default("test")',
],
];
namespace App;
use Illuminate\Database\Eloquent\Model;
class Foobar extends Model
{
protected $guarded = [];
}
namespace App\Http\Controllers;
use App\Foobar;
use Illuminate\Http\Request;
class FoobarController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$foobars = Foobar::all();
return response()->json([]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return response()->json([]);
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data = $request->validate([
'foo' => 'string|nullable',
'bar' => '',
]);
Foobar::create($data);
return response()->json([]);
}
/**
* Display the specified resource.
*
* @param Foobar $foobar
* @return \Illuminate\Http\Response
*/
public function show(Foobar $foobar)
{
return response()->json([]);
}
/**
* Show the form for editing the specified resource.
*
* @param Foobar $foobar
* @return \Illuminate\Http\Response
*/
public function edit(Foobar $foobar)
{
return response()->json([]);
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param Foobar $foobar
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Foobar $foobar)
{
$data = $request->validate([
'foo' => 'string|nullable',
'bar' => '',
]);
$foobar->update($data);
return response()->json([]);
}
/**
* Remove the specified resource from storage.
*
* @param Foobar $foobar
* @return \Illuminate\Http\Response
* @throws \Exception
*/
public function destroy(Foobar $foobar)
{
$foobar->delete();
return response()->json([]);
}
}
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class FoobarResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'foo' => $this->foo,
'bar' => $this->bar,
'notCamelCaseField' => $this->not_camel_case_field,
];
}
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFoobarTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('foobar', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('foo', 20)->default("test")->nullable();
$table->('bar');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('foobar');
}
}
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class FoobarRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'foo' => 'string|nullable',
'bar' => '',
];
}
}
/* @var $factory \Illuminate\Database\Eloquent\Factory */
use App\Foobar;
use Faker\Generator as Faker;
$factory->define(Foobar::class, function (Faker $faker) {
return [
'foo' => $faker->sentence(2),
'bar' => $faker->,
];
});
use Illuminate\Database\Seeder;
use App\Foobar;
class FoobarSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(Foobar::class, 33);
}
}