jeudi 7 septembre 2017

How to create a REST JSON API using Laravel 5.5 or Laravel 5.4

Am just starting out with laravel and i wanted to create a simple rest api that accepts json data and returns a json data but didnt seem to know how to do this. I was wondering if anyone could help. below is what i want my controller to look like or do:

class MembersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //return all members as json
    }

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        // get user values as json
        // save value to database
       // return user data as json.
    }

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //leave as empty
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //update value and return as json
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //delete value and also return deleted value as json
    }
}

How can i achieve the above using laravel. Mostly 5.5 or 5.4. I dont seem to find anything that could be of help anywhere.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire