condition profile id
This commit is contained in:
@@ -96,26 +96,22 @@ class TanamanController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
$profile = $user->profile->id;
|
$profile = $user->profile;
|
||||||
if(!$user->role === 'petani' && !$request->input('profile_id')) {
|
$profileId = $user->role === 'petani' ? $profile->id : $request->profile_id;
|
||||||
$profile = $request->input('profile_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$request->merge([
|
$request->merge([
|
||||||
'komoditas_id' => $request->input('komoditas.id') ?? $request->input('komoditas_id'),
|
'komoditas_id' => $request->input('komoditas.id') ?? $request->input('komoditas_id'),
|
||||||
'lahan_id' => $request->input('lahan.id') ?? $request->input('lahan_id'),
|
'lahan_id' => $request->input('lahan.id') ?? $request->input('lahan_id'),
|
||||||
'profile_id' => $profile->id
|
'profile_id' => $profileId,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
dd($request->all());
|
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'nama' => ['required', 'string', 'max:255'],
|
'nama' => ['required', 'string', 'max:255'],
|
||||||
'komoditas_id' => ['required', 'exists:master_komoditas,id'],
|
'komoditas_id' => ['required', 'exists:master_komoditas,id'],
|
||||||
'lahan_id' => [
|
'lahan_id' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::exists('map_lahan', 'id')->where(function ($query) use ($profile) {
|
Rule::exists('map_lahan', 'id')->where(function ($query) use ($profileId) {
|
||||||
$query->where('profile_id', $profile->id)
|
$query->where('profile_id', $profileId)
|
||||||
->whereNull('deleted_at');
|
->whereNull('deleted_at');
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user