public function show(Thread $thread)
{
if($thread->haveTypeId()) return redirect(route('api.thread.show', $thread->type_id));
return new ThreadResource($thread);
}
I have a nullable type_idcolumn in my thread table, I want to check if there is a type_id in given thread then redirect to thread url with type_id not id in table, So i redirects user to correct url but because i use return redirect i cannot reach to ThreadResource hence i give only blank page with no json.
use Illuminate\Http\Request;
public function show(Request $request, Thread $thread)
{
if ($request->expectsJson()) {
return new ThreadResource($thread);
}
if($thread->haveTypeId()) {
return redirect(route('api.thread.show', $thread->type_id));
}
}