1. Go to this page and download the library: Download armincms/many-to-many 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/ */
armincms / many-to-many example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
/**
* The users that belong to the role.
*/
public function users()
{
return $this->belongsToMany(User::class)->withPivot('id', 'active', 'created_by');
}
}
use Armincms\Fields\BelongsToMany;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
->fields(function() {
return [
Text::make('Price')
->rules('
use Armincms\Fields\BelongsToMany;
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [
BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
->fields(function() {
return [
Text::make('Price')
->rules('
use Armincms\Fields\BelongsToMany;
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [
BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
->fields(function() {
return [
Text::make('Price')
->rules('
use Armincms\Fields\MorphToMany;
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [
MorphToMany::make(__("Label"), 'relationName', RelatedResource::class)
->fields(function() {
return [
Text::make('Price')
->rules('
use Armincms\Fields\MorphedByMany;
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [
MorphedByMany::make(__("Label"), 'relationName', RelatedResource::class)
->fields(function() {
return [
Text::make('Price')
->rules('