yudy

Experience

120

0 Best Reply Awards

  • Member Since 6 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

10th January, 2018

yudy left a reply on -> OrWhereHas Failed Fetch Data From Multiple Tables • 6 months ago

I didn't test ilike to my local version with Mysql, but as you mention I think i will be a good idea to have support Mysql and Postgres, so I will try ASAP.

By the way how to use whereRaw with Has, is it whereRawHas?

9th January, 2018

yudy left a reply on -> OrWhereHas Failed Fetch Data From Multiple Tables • 6 months ago

Thanks alot for the explanation, by the way ilike works perfectly. bless you :)

yudy started a new conversation -> OrWhereHas Failed Fetch Data From Multiple Tables • 6 months ago

I'm using Laravel 5.2 and PostgreSql and deploy on Heroku

I have a search form to get data from multiple table >> books, writters, publisher and categories.

Here is the controller for the search form

public function search(Request $request)
    {
        $keyword = $request->input('keyword');
        

        // multiple query from different tables
        $query = Book::where('judul','like','%'.$keyword.'%')
        ->orWhere('label','like','%'.$keyword.'%')
        ->orWhere('isbn','like','%'.$keyword.'%')
        ->orWhere('status', 'like', '%'.$keyword.'%')
        ->orWhereHas('writter', function ($query) use ($keyword) {
            $query->where('nama_penulis', 'like', '%'.$keyword.'%');
        })
        ->orWhereHas('category', function ($query) use ($keyword) {
            $query->where('nama_kategori', 'like', '%'.$keyword.'%');
        })
        ->orWhereHas('publisher', function ($query) use ($keyword) {
            $query->where('nama_penerbit', 'like', '%'.$keyword.'%');
        });


        $book_list = $query->paginate(5);
        $pagination = $book_list->appends($request->except('page'));
        $total_book = $book_list->total();
        return view('dashboards.index', compact('book_list', 'keyword', 'pagination', 'total_book', 'nama_penulis'));
    }

the code works like a charm on the local using Mysql.

the problem is after i deploy to the Heroku and using Postgress, the search form only get data from the books table.

I wonder why its ignoring ->whereHas. Is it any explanation, or should I get different approach if using postgres?

24th December, 2017

yudy started a new conversation How To Handle Update On Image Upload • 6 months ago

Hi all i new to laravel

recently i try to practice with laravel 5.5 and create simple upload image task

here is my controller on store

        $input = $request->all();

 
        $this->validate($request, [ 
            'photo' => 'sometimes|image|mimes:jpeg,png,jpg,gif,svg|max:500',
        ]);
        


        if ($request->hasFile('photo')) {
            $photo = $request->file('photo');
            $ext = $photo->getClientOriginalExtension();

            if ($request->file('photo')->isValid()) {
                $photo_name = date('YmdHis'). ".$ext";
                $phptpName = time().'.'.$request->photo->getClientOriginalExtension();
                $request->photo->move(public_path('photo-upload'), $photoName);
                $upload_path = public_path('photo-upload');
                $input['photo'] = $photoName;
            }
        }

contoller on update


        if ($request->hasFile('photo')) {
            // delete the old/previous one
            $exist = Storage::disk('photo')->exists($student->photo);
            if (isset($student->photo) && $exist) {
                $delete = Storage::disk('photo')->delete($siswa->photo);
            }

            // upload new one
            $photo = $request->file('photo');
            $ext = $photo->getClientOriginalExtension();
            $photoName = time().'.'.$request->foto->getClientOriginalExtension();
            if ($request->file('photo')->isValid()) {
                $upload_path = 'photo-upload';
                $request->file('photo')->move($upload_path, $phptpName);
                $input['photo'] = $iphotoName;
            }
        }

the store method works perfectly, it uploaded image to the right folder then update the databse

the problem is on the update, it update the database but it didn't upload the image to the photo-upload folder

Any suggestion?

Thanks

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.