further development of the predefinedmutations
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Dynamic;
|
||||
use App\Models\Ledger;
|
||||
use App\Models\PredefinedMutation;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -15,20 +16,21 @@ class PredefinedMutationController extends Controller
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Dynamic $dynamic)
|
||||
public function index(Dynamic $dynamic, Ledger $ledger)
|
||||
{
|
||||
$this->authorize('update', $dynamic);
|
||||
|
||||
return Inertia::render('Dynamics/PredefinedMutations/Index', [
|
||||
return Inertia::render('Ledgers/PredefinedMutations/Index', [
|
||||
'dynamic' => $dynamic,
|
||||
'predefined_mutations' => $dynamic->predefinedMutations()->latest()->get(),
|
||||
'ledger' => $ledger,
|
||||
'predefined_mutations' => $ledger->predefinedMutations()->latest()->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request, Dynamic $dynamic)
|
||||
public function store(Request $request, Dynamic $dynamic, Ledger $ledger)
|
||||
{
|
||||
$this->authorize('update', $dynamic);
|
||||
|
||||
@@ -36,11 +38,10 @@ class PredefinedMutationController extends Controller
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'amount' => ['required', 'integer'],
|
||||
'type' => ['required', 'string', 'in:reward,penalty'],
|
||||
]);
|
||||
|
||||
$dynamic->predefinedMutations()->create($request->all());
|
||||
$ledger->predefinedMutations()->create($request->all());
|
||||
|
||||
return redirect()->route('dynamics.predefined-mutations.index', $dynamic);
|
||||
return redirect()->route('dynamics.ledgers.predefined-mutations.index', [$dynamic, $ledger]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ class Ledger extends Model
|
||||
return $this->hasMany(Mutation::class);
|
||||
}
|
||||
|
||||
public function predefinedMutations(): HasMany
|
||||
{
|
||||
return $this->hasMany(PredefinedMutation::class);
|
||||
}
|
||||
|
||||
public function media(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||
{
|
||||
return $this->morphMany(Media::class, 'mediable');
|
||||
|
||||
@@ -11,15 +11,14 @@ class PredefinedMutation extends Model
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'dynamic_id',
|
||||
'ledger_id',
|
||||
'name',
|
||||
'description',
|
||||
'amount',
|
||||
'type',
|
||||
];
|
||||
|
||||
public function dynamic(): BelongsTo
|
||||
public function ledger(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Dynamic::class);
|
||||
return $this->belongsTo(Ledger::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user