Eudemon

Eudemon

Member Since 1 Year Ago

Experience Points
150
Total
Experience

4,850 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
150 XP
Dec
21
9 months ago
Activity icon

Replied to Adding New API Endpoint

Yes I can use my existing model class but I am doing this not for any project, just to learn more about laravel so I am purposely do anything I haven't done before

Activity icon

Replied to Adding New API Endpoint

@STEVECOVE - no I don't, I suppose that's where I should start

Activity icon

Replied to Adding New API Endpoint

@STEVECOVE - the query builder is for my regular controller, I do want to use eloquent model,

in the example it uses existing user table https://laravel.com/docs/5.7/eloquent-resources#writing-resources

but how do I make it use my own table, I have tried @kobear suggestion adding table name in the class

Activity icon

Replied to Adding New API Endpoint

Model class namespace is correct, I have used it in my normal controllers

and yes I have use App\Http\Resources\MovieResource; in API controller

how does MovieResource know which table to pull? shouldn't I specific that? or DI my model?

<?php

namespace App\Http\Controllers;

use App\Http\Resources\MovieResource;
use Illuminate\Http\Request;

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

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

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

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

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

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

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

Activity icon

Replied to Adding New API Endpoint

@douglasakula @stevecove

verified that I have migration and seeding done for the table i need to pull, it seems like I am missing the model that controller talk to database

I have resource file with

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class MovieResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'type' => 'movie',
            'id' => $this->id,
            'title' => $this->title,
            'format' => $this->format
        ];
    }
}

controller file that's boiler plate from running make:controller --resource controller

namespace App\Http\Controllers;
public function show($id)
    {
        return new MovieResource($id);
    }

I already have a model class that makes the DB call for get, update, delete operation for regular routes that retrieve data, which looks like this

namespace App\Http\Models;
public function get($num = null){
        if ($num === null){
            $return = DB::table('movie')->get();
        } else {
            $return = DB::table('movie')->select()->limit($num)->get();
        }

        return $return;
    }

but I don't know how to connect this to my API route which is Route::get('movie/{id}', '[email protected]');

Dec
20
9 months ago
Activity icon

Started a new conversation Adding New API Endpoint

I have a custom table created and stored custom data,

I want to create API end point to retrieve data from that table,

all the guides I read tells me to create a resource and resource controller,

then add the route to api.php

with a toArray function in CustomResource returning 'id' 'fields', but how does laravel know i want to pull my custom table? I don't see how they are linked together

when I access the api url /api/custom/{id} it return class 'custom' does not exist