Last active
December 21, 2020 18:12
-
-
Save ennjoy/67c72ad415514d5a8dd3b62cb513835a to your computer and use it in GitHub Desktop.
WallController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Models\Wall; | |
use App\Models\Users; | |
use App\Models\Pages; | |
use App\Http\Resources\WallResource; | |
use App\Http\Resources\UsersResource; | |
use App\Http\Resources\PagesResource; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Auth; | |
class WallController extends Controller | |
{ | |
public function get(Request $request) | |
{ | |
$owner_id = $request->input('owner_id') ?? Auth::user()->id; | |
$items = Wall::where('owner_id', $owner_id)->orderByDesc('id')->get(); | |
// $arPlus = $items->where('form_id', '>', 0)->toArray(); | |
// $arMinus = $items->where('form_id', '<', 0)->toArray(); | |
// var_dump($arPlus); | |
return [ | |
'items' => WallResource::collection($items), | |
// 'users' => UsersResource::collection(Users::whereIn('id', $from_id)->get()), | |
// 'pages' => PagesResource::collection(Pages::whereIn('id', $from_id)->get()) | |
]; | |
} | |
public function post(Request $request) | |
{ | |
$validate = $this->validate($request, [ | |
'text' => 'required|string|min:1|max:1024' | |
]); | |
$validate['from_id'] = Auth::user()->id; | |
$validate['owner_id'] = $request->owner_id ?? Auth::user()->id; | |
$data = Wall::create($validate); | |
return ['id' => $data->id]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment