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.');