1use Illuminate\Database\Eloquent\Builder;
2
3// Retrieve posts with at least one comment containing words like foo%...
4$posts = App\Post::whereHas('comments', function (Builder $query) {
5 $query->where('content', 'like', 'foo%');
6})->get();
7
8// Retrieve posts with at least ten comments containing words like foo%...
9$posts = App\Post::whereHas('comments', function (Builder $query) {
10 $query->where('content', 'like', 'foo%');
11}, '>=', 10)->get();
1use Illuminate\Database\Eloquent\Builder;
2
3// Retrieve posts with at least one comment containing words like code%...
4$posts = Post::whereHas('comments', function (Builder $query) {
5 $query->where('content', 'like', 'code%');
6})->get();
7
8// Retrieve posts with at least ten comments containing words like code%...
9$posts = Post::whereHas('comments', function (Builder $query) {
10 $query->where('content', 'like', 'code%');
11}, '>=', 10)->get();
1public function destroy($id){
2
3 $res=User::find($id)->delete();
4 if ($res){
5 $data=[
6 'status'=>'1',
7 'msg'=>'success'
8 ];
9 }else{
10 $data=[
11 'status'=>'0',
12 'msg'=>'fail'
13 ];
14 return response()->json($data);
15
1$users = User::with('podcasts')->get();
2
3foreach ($users->flatMap->podcasts as $podcast) {
4 echo $podcast->subscription->created_at;
5}