This is the code. I am doing this to approve a post done by user, as an admin. I keep getting the same error message, Creating default object from empty value. What do i do please help me. Is it an error on the code or something else at all. This is my assignment.
<th class="px-2 py-1 text-2xl font-bold text-left">TYPE</th>
<th class="px-2 py-1 text-2xl font-bold text-left" v-if="$page.user.userType != 'user'" >APPROVAL</th>
</tr>
<tr v-for="(campaign, index) in campaign.data" :class="{'bg-gray-300': index%2 === 0}"> <!-- v-if=" campaign.approve == 1 -->
<td class="px-2 py-3 text-xl text-left"></td>
<td class="px-2 py-3 text-xl text-left"></td>
<td class="px-2 py-3 text-xl text-left"></td>
<td class="px-2 py-3 text-xl text-left"></td>
<td v-if="$page.user.userType != 'user'">
<form @submit.prevent="handleApproval">
<select v-model="campaign.approve">
<option value="1">Approve</option>
<option value="0">Disapprove</option>
</select>
<!-- <input type="checkbox" v-model="campaign.approve" :true-value="1" :false-value="0" > -->
<button class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded">
Done
</button>
</form>
</td>
</tr>
</table>
<div class="p-5 flex">
Controller
public function update(Request $request, Campaign $campaign)
{
$data = request()->validate([
'approve' => 'required',
]);
$campaign->update($data);
return redirect()->to('campaign');
}
/**
* Remove the specified resource from storage.
*
* @param AppModelsCampaign $campaign
* @return IlluminateHttpResponse
*/
public function destroy(Campaign $campaign)
{
//
}
public function approval(Request $request){
$campaign = Campaign::find($request->id);
$approveVal = $request->approve;
if ($approveVal=='on') {
$approveVal=1;
}else {
$approveVal=0;
}
$campaign->approve=$approveVal;
$campaign->save();
return redirect()->route('campaign.index');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire