PHP code example of julio / capyrel

1. Go to this page and download the library: Download julio/capyrel 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/ */

    

julio / capyrel example snippets


public function posts(): HasMany
{
    return $this->hasMany(Post::class);  // capyrel: posts.user_id
}

public function roles(): BelongsToMany
{
    return $this->belongsToMany(Role::class);  // capyrel: pivot: role_user
}

public function index(Request $request)
{
    $query = User::query()->with(['posts', 'profile', 'roles'])
        ->withCount(['posts', 'profile', 'roles']);

    if ($request->search) {
        $query->where('name', 'like', "%{$request->search}%");
    }

    $users = $query->latest()->paginate(15);

    return view('users.index', compact('users'));
}

public function rules(): array
{
    return [
        'title'   => [' ];
}

describe('User relationships', function () {
    it('User::posts() returns a HasMany', function () {
        expect((new User)->posts())->toBeInstanceOf(HasMany::class);
    });

    it('User can attach Role', function () {
        $user = User::factory()->create();
        $role = Role::factory()->create();
        $user->roles()->attach($role->id);
        expect($user->fresh()->roles)->toHaveCount(1);
    })->skip('Remove skip() to enable DB test');
});

// In any controller:
return redirect()->route('posts.index')->with('success', 'Post created.');
return redirect()->back()->with('error', 'Could not save changes.');
return redirect()->back()->with('warning', 'Image too large, resized automatically.');
return redirect()->back()->with('info', 'Changes will take effect after the next sync.');

'pagination' => ['per_page' => 15, 'type' => 'paginate'],

'features' => [
    'transaction_pivots' => true,  // wrap pivot syncs in DB::transaction()
    'json_responses'     => true,  // $request->wantsJson() dual responses
    'search'             => true,  // search block in index()
    'soft_deletes'       => true,  // restore/forceDelete methods
],

'spatie' => [
    'media_library'  => true,   // auto-detected from composer.json
    'permissions'    => true,
],
bash
php artisan capyrel:new
bash
php artisan migrate
php artisan model:scaffold   # controllers + routes
bash
php artisan model:scaffold
bash
php artisan capyrel:new
# > a blog with posts, tags, categories, authors, and comments
# → Post, Tag, Category, Author, Comment

php artisan migrate
php artisan model:scaffold
php artisan model:resources    # API Resources with whenLoaded()
php artisan model:requests     # StorePostRequest, UpdatePostRequest
php artisan model:tests        # Pest relationship tests
php artisan capyrel:openapi    # OpenAPI 3.0 spec
bash
php artisan capyrel:new
# > Article, Author, Publication, Tag, Bookmark

php artisan migrate
php artisan model:scaffold --models --controllers --routes
php artisan model:resources    # API Resources
php artisan model:requests     # validation
php artisan capyrel:openapi    # docs
php artisan capyrel:typescript # types for frontend
php artisan capyrel:postman    # ready-to-import collection
bash
php artisan capyrel:new              # interactive wizard
php artisan capyrel:new --force      # skip all confirmations
php artisan capyrel:new  # Python auto-detected; falls back to PHP if unavailable
bash
# API Resources — N+1-proof via whenLoaded()
php artisan model:resources
php artisan model:resources User --force

# Form Requests — rules derived from column types + constraints
php artisan model:requests
php artisan model:requests Post
bash
php artisan model:tests
php artisan model:tests User
php artisan model:tests --dry-run
bash
php artisan model:factory
php artisan model:factory Post
php artisan model:seed
bash
php artisan model:broadcast Post
# → PostCreated, PostUpdated, PostDeleted events + channels

php artisan model:notifications Post
# → PostNotification class with mail + database channels

php artisan model:livewire Post
# → PostIndex, PostForm Livewire components (
bash
php artisan capyrel:openapi     # OpenAPI 3.0 YAML spec
php artisan capyrel:typescript  # TypeScript interfaces
php artisan capyrel:postman     # Postman collection JSON
php artisan capyrel:graphql     # GraphQL schema SDL
bash
php artisan vendor:publish --tag=capyrel-config