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