nikoslykos

nikoslykos

Member Since 2 Years Ago

Experience Points 540
Experience
Level
Lessons Completed 2
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

24 May
6 months ago

nikoslykos started a new conversation Laravel(API) + Angular 5 - How To Log Out User

Because i dont use the default laravel authentication but a custom authcontroller, how do i logout a user? This is the code from the AuthController.

<?php 
 
namespace App\Http\Controllers; 
 
use App\User; 
use Illuminate\Http\Request; 
use App\Http\Controllers\Controller; 
use Illuminate\Support\Facades\Auth; 
use Validator; 
 
class AuthController extends Controller 
{ 
   
    public function login(Request $request) 
    { 
        Auth::attempt(['email' => request('email'), 'password' => request('password')]); 
        return redirect('/auth_status'); 
    } 
 
    public function authStatus()  
    {     
        if (Auth::check()) { 
            return response()->json(['Authenticated' => true]); 
        } 
        else  
            return response()->json(['Authenticated'=> false]); 
    } 
 
    public function register(Request $request) 
    { 
        $validator = Validator::make($request->all(), [ 
            'email' => 'required|email', 
            'password' => 'required' 
        ]); 
         
        if ($validator->fails()) { 
            return response()->json(['error'=>$validator->errors()], 401);             
        } 
 
        $input = $request->all(); 
        $input['password'] = bcrypt($input['password']); 
        $user = User::create($input); 
        $success['name'] =  $user->name; 
 
        return response()->json(['success'=>$success], $this->successStatus);     
    } 
 
} 

Then Angular Takes the XSRF Token and is logged in. How do i logout? Can i use auth::logout ? Or it doesnt work that way? Do i have to destroy the token? If yes how?

06 May
7 months ago

nikoslykos left a reply on How To Query Many To Many Relationship Using Eloquent.

My problem is i can't find how to do that with a resource..

nikoslykos started a new conversation How To Query Many To Many Relationship Using Eloquent.

Hey guys, i need some help with something. I'll provide the code needed first.

SalesController


<?php

namespace App\Http\Controllers\Sales;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Models\Sales;
use App\Http\Resources\Sales as SalesResource;

class SalesController extends Controller
{
    
public function show($id)
{
$user = Auth::id();
$invoice =Sales::findOrFail($id)->products_in_sales()->where('sales.id',$id)->where('sales.user_id',$user)->first();
       
return new SalesResource($invoice); 
}

Sales Model


<?php

namespace App\Models\Sales;

use Illuminate\Database\Eloquent\Model;

class Sales extends Model 
{

    protected $table = 'sales';
    public $timestamps = true;
    protected $fillable = array('id', 'client_id', 'user_id', 'invoice_number', 'type');

    public function products_in_sales()
    {
        return $this->belongsToMany('App\Models\Products','products_sales','invoice_id','product_id');
    }

}

Sales Resource


<?php

namespace App\Http\Resources\Sales;

use Illuminate\Http\Resources\Json\JsonResource;

class Sales extends JsonResource
{

    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'client_id' => $this->client_id,
            'user_id' => $this->user_id,
            'invoice_number' => $this->invoice_number,
            'type' => $this->type
        ];
    }
}

I have 3 tables : Sales , Products and a pivot table products_sales. In products table i save each product with the sale_id so i need to bind one sale with the products. I have set the relation in my sales_model but i dont understand how exactly i can do that. What i have wrote on sales controller, does it seem correct? or there is a better way?

25 Oct
1 year ago

nikoslykos left a reply on Question About Creating An API

Thanks. I want to ask one more thing. What's the difference between a resource and a collection? how do i decide when to use on of them?

nikoslykos left a reply on Question About Creating An API

Thank you i will watch it ! But can you tell me whats the difference to what i asked?

nikoslykos started a new conversation Question About Creating An API

I am building an API and there is something i can't fully understand. In Laravel's documentation at Eloquent ORM section there is something called API Resources. what does this do ? What i did now is:

  1. i created a model and specified what table in my db should be used

  2. i created the controller

    public function index() { $clients= Clients::all(); return response()->json($clients); }

  3. And created the route at api.php

    Route::get('clients','[email protected]');

It works fine (tried it with Postman). Is there any difference if i used Resources?

(https://laravel.com/docs/5.5/eloquent-resources)

19 Oct
1 year ago

nikoslykos started a new conversation How To Use Passport With SPA

I want to make a web app with laravel as backend and probably angular for the frontend. My problem is now that i have no idea how to use Passport...Laravel will work ONLY as api server so the SPA must login and register through the api. But also i want to give access outside of the spa (if the user wants it). Can anyone help me with this? I have been searching for about a month and i cant find anything...i checked the documentation but its way too complicated...

17 Oct
1 year ago

nikoslykos started a new conversation How To Make A Rest Api

Hello, i'm on to making an app with laravel as backend server and angular or vuejs for frontend. Can anyone suggest me a good tutorial or course on how to make a rest api in laravel ? + I need some help with passport... i really cannot understand how it works and especially how you can register a new user...i dont see anything in the passport routes... And one last thing, is lumen better for api's ?

29 Aug
1 year ago

nikoslykos left a reply on Laravel 5.4 With Passport

So even with passport users still register from the login system you make from make:auth ?

nikoslykos started a new conversation Laravel 5.4 With Passport

I want to make an app with Laravel as an api server and i will use the api with vue.js. I installed passport in my Laravel project. I saw that i have some routes that passport created, i saw some videos online but i got really confused about how this really works... How am i supposed to register a new user through passport? I want to use the api at the frontend app with vue.js but i need to use the api outside of my app. Where can i start? This is really confusing...