Monday, August 10, 2020

Crud Files

Tags

 Controller

    userform.php


<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\userbook;
use App\country;
use App\state;
use App\city12;

class userform extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $user = userbook::all();
        return view('admin.user.viewuser')->with('userpass',$user);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //


        $usercountry=country::pluck('countryname','id');
        $userstate=state::pluck('statename','id');
        $usercity=city12::pluck('cityname','id');

        $data=array('usercountry'=>$usercountry,'userstate'=>$userstate,'usercity'=>$usercity);

        return view('admin/user/create')->with($data);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        $user = new userbook();

        $user->fname=$request->input('fname');
        $user->gender=$request->input('gender');
        $vehicleString = implode(",",  $request->input('hobby') );

        $user->hobby=$vehicleString;
        $user->countryname=$request->input('countryname');
        $user->statename=$request->input('statename');
        $user->cityname=$request->input('cityname');

        $user->save();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
        $usermodel=userbook::find($id);

        $usercountry=country::pluck('countryname','id');
        $userstate=state::pluck('statename','id');
        $usercity=city12::pluck('cityname','id');

        $userradio=userbook::pluck('gender','id');

       $data=array('usermodel'=>$usermodel,'usercountry'=>$usercountry,'userstate'=>$userstate,'usercity'=>$usercity,
       'userradio'=>$userradio);

        return view('admin.user.userupdate')->with($data);

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
        $useruserbook::find($id);

        $user->fname=$request->input('fname');
        $user->gender=$request->input('gender');
        $vehicleString = implode(",",  $request->input('hobby') );

        $user->hobby=$vehicleString;
        $user->countryname=$request->input('countryname');
        $user->statename=$request->input('statename');
        $user->cityname=$request->input('cityname');

        $user->save();

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
        $user = userbook::find($id);

        $user->delete();

        return redirect('admin/user/')->with('sucess','sucessfully deleted..');
    }
}


EmoticonEmoticon