<?php

namespace App\Http\Controllers\Api\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Portfolio;

class PortfolioController extends Controller
{
    public function index()
    {
        return Portfolio::where('jobseeker_id', auth()->user()->jobseeker->id)->get();
    }

    public function store(Request $request)
    {
        $data = $request->validate([
            'title' => 'required'
        ]);

        $data['jobseeker_id'] = auth()->user()->jobseeker->id;

        return Portfolio::create($data);
    }

    public function update(Request $request, $id)
    {
        $item = Portfolio::findOrFail($id);

        $item->update($request->all());

        return $item;
    }

    public function destroy($id)
    {
        Portfolio::destroy($id);

        return response()->json(['message'=>'deleted']);
    }
}