<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Client;
class clientController extends Controller
{
    public function index()
    {
        $search = \Request::get('search');
        $data = Client::where('nama','like','%'.$search.'%')->orderBy('id')->paginate(6);

    	//$data = Client::all();
    	return view('client')->with('data', $data);
    }

    public function create(){
    	return view('tambahclient');
    }

    public function store(Request $request){
		Client::create($request->all());

		return redirect('client');
    }

    public function edit($id){
    	$data = Client::find($id);
    	return view('editclient')->with('data', $data);
    }

    public function update(Request $request, $id){
    	//update client set ... - ... where id = $id
    	Client::find($id)->update($request->all());

    	return redirect('client');
    }

    public function destroy($id){
    	Client::find($id)->delete();

    	return redirect('client');
    }

    public function search(Request $request, $nama)
    {
        $search = Input::get('nama');

        if ($search){

            $hasil = Client::find($nama);
            $data = $hasil->where('nama', 'LIKE', '%'. $search .'%')->get();

            return view('detailclient')->with('data', $data);
             }
    }

}
