Kaziux

Kaziux

Member Since 2 Months Ago

Experience Points
420
Total
Experience

4,580 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 your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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
420 XP
Oct
29
1 day ago
Activity icon

Replied to I Get 302 Response Instead Of 200 When Capturing Screenshot And User Not Keep Logged In On The Chrome Extension

I use laradock, prebuilt thing for PHP projects. Trying on localhost same issue.

Oct
28
2 days ago
Activity icon

Replied to I Get 302 Response Instead Of 200 When Capturing Screenshot And User Not Keep Logged In On The Chrome Extension

My upload image size is smaller than 1MB, it depends where you want capture screenshot. My host is running on docker VM. If I upload huge size image, I should get 500 error.

Activity icon

Replied to I Get 302 Response Instead Of 200 When Capturing Screenshot And User Not Keep Logged In On The Chrome Extension

Yeah, I thought about CORS thing, but without cors, I am not able to do any requests from extension, I'm allowed to do requests from extension in cors config file. CSRF I'm allowed all api routes exception by default.

Activity icon

Replied to I Get 302 Response Instead Of 200 When Capturing Screenshot And User Not Keep Logged In On The Chrome Extension

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ImageRequest extends FormRequest
{
 
    public function authorize()
    {
        return true;
    }
    public function rules()
    {
        return [
            'image' => 'required'
        ];
    }
}
`
Activity icon

Started a new Conversation I Get 302 Response Instead Of 200 When Capturing Screenshot And User Not Keep Logged In On The Chrome Extension

Hello, I have one strange issue. I get 302 response instead of 200 when capturing screenshot on chrome extension. Also, user can't keep logged in, despite having JWT token and as a result he must login repeatdly. I'm using Laravel as back-end with api auth. P.S. I do everything same with Java Springboot as a back-end it works like a charm. login.js

const url = 'http://local.requestmapper.com/api/ext/user/';


var form = document.getElementById('login_form');
document.getElementById("login_form").addEventListener("submit", login);

getUser();

form.addEventListener('submit', function (event) {
   

    var form = document.getElementById('login_form');

        var formData = new FormData();
        for (var i = 0; i < form.length; ++i) {
            formData.append(form[i].name, form[i].value)
        }

    fetch(url + 'login', {
        method: 'post',
        credentials: 'same-origin',
        mode: 'no-cors',
        cache: 'default',
        body: formData,
    })
        .then((response) => response.json())
        .then( (data) => {
            var token = data.token;
            console.log(token);
            localStorage.setItem('token', token);
            window.location.href = 'user.html';
        })
            .catch((error) => {
                console.log('Error:', error);
             })

    event.preventDefault();
})


function getUser() {

    var token = localStorage.getItem('token');

    fetch(url + 'check', {
        method: 'get',
        credentials: 'same-origin',
        cache: 'default',
        headers: { 'Authorization': 'Bearer  ' + token},
        mode: 'cors',
    })
        .then(response => {
            console.log(response.status)
            if (response.ok) {
                window.href.location = 'user.html';
            }
            return response.json();
        })
        .catch((error) => {
            console.log(error);
        })

}

app.js

const url = 'http://local.requestmapper.com/api/ext/user/';

document.getElementById('logout').addEventListener("click", logout);
document.getElementById('takess').addEventListener("click", takess);


getUser();

async function logout() {

    var token = localStorage.getItem('token');
  
    await fetch(url + 'logout', {
        method: 'post',
        credentials: 'same-origin',
        headers: {
            'Authorization': 'Bearer  ' + token,
        },
        mode: 'cors',
    })
        .then(data => data.json())
        .then( data =>{
            console.log(data);
            localStorage.removeItem('token');
            window.location.href = 'popup.html'
        })
        .catch((error) => {
            console.log(error);
        });
    event.preventDefault();
}

function takess() {

    //var token = localStorage.getItem('token');

    chrome.tabs.captureVisibleTab(null, {}, function (canvas) {
        upload(canvas);
        /*fetch(url + 'upload', {
            method: 'post',
            credentials: 'same-origin',
            headers: {
                'Authorization': 'Bearer  ' + token,
                'Content-Type':  'form-data',
            },
            mode: 'cors',
            body: JSON.stringify({ 'image': canvas }),
        })
            .then(response => console.log(response))
            .catch(error => console.log(error))*/
    });
    event.preventDefault();
}


function upload(canvas) {
    var token = localStorage.getItem('token');

    fetch(url + 'upload', {
        method: 'post',
        credentials: 'same-origin',
        headers: {
            'Authorization': 'Bearer  ' + token,
            'Content-Type': 'form-data',
        },
        mode: 'cors',
        body: JSON.stringify({ 'image': canvas }),
    })
        .then(response => console.log(response))
        .catch(error => console.log(error))
}

function getUser() {

    var token = localStorage.getItem('token');
  
    fetch(url + 'check', {
        method: 'get',
        credentials: 'same-origin',
        headers: {
            'Authorization': 'Bearer  ' + token,
        },
        mode: 'cors',
    })
        .then(response => {           
            response.json();
            console.log(response.json());
            if (!response.ok) {
                window.href.location = 'popup.html';
            }
        })
        .catch((error) => {
            console.log(error);
        })
}

ExtensionController.php

<?php

namespace App\Http\Controllers;


use App\Http\Requests\ImageRequest;
use App\Http\Requests\LoginRequest;
use App\Http\Requests\TestRequest;
use App\User;

use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Facades\JWTAuth;

class ExtensionController extends Controller
{

    public function login(LoginRequest $request)
    {
        $credentials = $request->only('email', 'password');

        if ($token =  JWTAuth::attempt($credentials)) {

            return response()->json(['status' => 'success', 'token' => $token], 200)->header('Authorization', $token);
        }
        return response()->json(['error' => 'Login failed'], 401);

    }


    public function uploadImage(ImageRequest $request)
    {

        $imagedata = str_replace(['data:image/jpeg;base64','data:image/png;base64'], '', $request->input('image'));

        $imagedata = str_replace('', '+', $imagedata);

        $imagedata = base64_decode($imagedata);

        $source = imagecreatefromstring($imagedata);

        $rotate = imagerotate($source, 0, 0);

        $imagename = storage_path('app/screenshots/') . time() . '.jpg';

        imagejpeg($rotate, $imagename, 100);

        return response()->json(['status' => 'success'], 200);
    }

    public function check(){
        if(Auth::guard('api')->check())
            return response()->json(['status' => 'User logged in'], 200);
    }

    public function refresh()
    {
        if($token = $this->guard('api')->refresh()){
            return response()
                ->json(['status' => 'success'], 200)
                ->header('Authorization', $token);
        }
        return response()->json(['error' => 'Token refresh error'], 401);
    }

    public function logout()
    {
        $this->guard('api')->logout();
        return response()->json([
           'status' => 'success',
            'msg' => 'Logged out successfully'
        ], 200);
    }

    private function guard()
    {
        return Auth::guard();
    }
}
Sep
18
1 month ago
Activity icon

Replied to Refactor ModelNotFoundException Response Into Vue Page

I thought, that there is simpler way. For me now only needs 404 modelnotfoundexception response shown in vue 404 error page.

Sep
17
1 month ago
Activity icon

Started a new Conversation Refactor ModelNotFoundException Response Into Vue Page

I have one interesting question. Is it possible refactor ModelNotFoundException 404 error response into vue page, which would be suitable for end users? I've already overriding ModelNotfoundexception message in Handler

<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Throwable;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  \Throwable  $exception
     * @return void
     *
     * @throws \Exception
     */
    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @throws \Throwable
     */
    public function render($request, Throwable $exception)
    {
        if($exception instanceof ModelNotFoundException){
            return response()->json([
                'error' => 'Entry for '.str_replace('App\','', $exception->getModel()).' not found'], 404);    
        }

        return parent::render($request, $exception);
    }
}
Controller 
Sep
09
1 month ago
Activity icon

Started a new Conversation Proper Dynamic Form Request Refactor And Accurately Working

Hello. I have issue when I'm trying refactor dynamic form validation into form request. Main issue is I get validation errors despite my form is filled. Also, custom validation rule doesn't work properly when logged in user email can't be validated and validation error messages should be more readable to users My controller

use App\Http\Requests\InviteRequest;
use App\Invitations;
use Illuminate\Support\Facades\Auth;
use App\User;
use App\Team;
use Notification;
Use App\Notifications\InviteNotification;
use App\Notifications\RegisterNotification;
use Str;
use URL;
use App\Organization;

class HomeController extends Controller{

   public function inviting(InviteRequest $request)
    {
        $invites = $request->validated('invite_array');

            foreach ($invites as $invite) {
                if (!User::where('email', $invite['email'])->first()) {
                    $this->process($invite['email'], 'register', 'RegisterNotification', null);
                }
                else {
                    if (User::where('email', $invite['email'])->first()->id != User::where('email', $invite['email'])->with('team')->first()->pivot['user_id']
                        && $invite['team_id'] != Team::user()->wherePivot('team_id', $invite['team_id']))
                    {
                        $this->process($invite['email'], 'invite', 'InviteNotification', $invite['team_id']);
                    } else {
                        return response()->json([
                            'status' => 'You cant invite user who is already on the team'
                        ], 403);
                    }
                }
            }

    }
}

InviteRequest

use Illuminate\Foundation\Http\FormRequest;
use App\Rules\InviteHimself;

class InviteRequest extends FormRequest{

  public function rules()
    {
        $rules = [];

        for($i = 0; $i < count($this->invite_array); $i++)
        {
            $rules['invite_array   '.$i.'  email'] = ['required', new InviteHimself()];

            $rules['invite_array  '.$i.'  team_id'] = 'required';
        }

        return $rules;
    }

    public function messages()
    {
        $messages = [];

        for($i = 0; $i<count($this->invite_array); $i++)
        {
            $messages['email '.' '.$i.' '.'.required'] = 'The email field'.$i.'must be :required';
            $messages['team_id '.' '.$i.'   '.'.required'] = 'The email field'.$i.'must be :required';
        }

        return $messages;
    }
}

InviteHimslef custom validation rule

use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Auth;


class InviteHimself implements Rule
{

    public function __construct()
    {
        //
    }

    public function passes($attribute, $value)
    {
        return $value == Auth::user()->first()->email;
    }

    public function message()
    {
        return 'You cant invite yourself';
    }
}
Aug
27
2 months ago
Activity icon

Replied to Call To A Member Function Map() On Null On Spatie Tags Field

But if I use tags field for more than one table, must I defined relationship beetwen them in general? Edit: Everything works alright but I can't preview all records I get Argument 1 passed to Spatie\TagsField\Tags::Spatie\TagsField\{closure}() must be an instance of Spatie\Tags\Tag, instance of App\Tag given Only hideFromIndex, hideFromDetail prevents from this error, but i want to see tags on previewing all records or seperatly.

Aug
26
2 months ago
Activity icon

Started a new Conversation Call To A Member Function Map() On Null On Spatie Tags Field

I get ```call to a member function map() on null`` when i use this spatie tag field package. I'm using Laravel 7.x version and Nova 3.x. Is neccessary to create table for tags?

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Benjacho\BelongsToManyField\BelongsToManyField;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Date;
use Spatie\TagsField\Tags;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;

  public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            BelongsTo::make('Brand', 'brand', 'App\Nova\Brand'),
            Text::make('Name', 'name')->rules('required'),

            Textarea::make('Statement', 'statement')->rules('required'),
	   Tags::make('Search Tags', 'search_tags');

	    Number::make('Priority', 'priority')->min(1)->max(10)->rules('required'),
            Select::make('Time frame', 'time_frame')->options([
                'Next Month' => 'Next Month',
                'Next 3 Months' => 'Next 3 Months',
                'Next 6 Months' => 'Next 6 Months',
                'Next 12 Months' => 'Next 12 Months',
            ])->rules('required'),
            Select::make('Successive meassure', 'success_measure')->options([
                'New Unique Visitors' => 'New Unique Visitors',
                'Beverages Sold' => 'Beverages Sold',
                'New Unique Customers' => 'New Unique Customers',
            ])->rules('required'),
            BelongsToManyField::make('Objective Owner', 'users', 'App\Nova\User')->relationModel(\App\Objectives::class)->rules('required'),
            Date::make('Review date', 'review_date')->rules('required'),
            Select::make('Status', 'status')->options([
                'Proposed' => 'Proposed',
                'Active' => 'Active',
                'Achieved' => 'Achieved'
            ])->rules('required'),
Aug
25
2 months ago
Activity icon

Replied to Method Illuminate\Validation\Validator::validateRequird Does Not Exist, When Using BelongsToManyField Field

Ok, I solved this silly issue. But now I get this error when trying to insert foreign values to pivot tables. SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (request_mapper.objectives_users, CONSTRAINT objectives_users_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE) (SQL: insert into objectives_users (objectives_id, user_id) values (1, 15))

Activity icon

Started a new Conversation Method Illuminate\Validation\Validator::validateRequird Does Not Exist, When Using BelongsToManyField Field

When I'm using Benjacho https://novapackages.com/packages/benjacho/belongs-to-many-field belongstomanyfield and try insert data. I get Method Illuminate\Validation\Validator::validateRequird does not exist. I assume is spelling mistake of package field validation. Source code:

<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\BelongsToMany;
use Benjacho\BelongsToManyField\BelongsToManyField;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Date;
use Spatie\TagsField\Tags;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            BelongsTo::make('Brand', 'brand', 'App\Nova\Brand'),
            Text::make('Name', 'name')->rules('required'),

            Textarea::make('Description', 'description')->rules('required'),
            
            Textarea::make('Search tags', 'search_tags')->rules('required'),

            Number::make('Priority', 'priority')->min(1)->max(10)->rules('required'),
            Select::make('Time frame', 'time_frame')->options([
                'Next Month' => 'Next Month',
                'Next 3 Months' => 'Next 3 Months',
                'Next 6 Months' => 'Next 6 Months',
                'Next 12 Months' => 'Next 12 Months',
            ])->rules('required'),
            Select::make('Successive meassure', 'success_measure')->options([
                'New Unique Visitors' => 'New Unique Visitors',
                'Beverages Sold' => 'Beverages Sold',
                'New Unique Customers' => 'New Unique Customers',
            ])->rules('required'),
            BelongsToManyField::make('Objective Owner', 'user', 'App\Nova\User')->relationModel(\App\Objectives::class)->rules('required'),
            Date::make('Review date', 'review_date')->rules('requird'),
            Select::make('Status', 'status')->options([
                'Proposed' => 'Proposed',
                'Active' => 'Active',
                'Achieved' => 'Achieved'
            ])->rules('required'),


        ];
    }
Aug
20
2 months ago
Activity icon

Replied to Refactor Blade Code Into Vue Code

@bobbybouwmann your idea did a trick. Thanks for that. It's possible to do, when I select certain organization, in team field, shows teams which belong to selected organization.

Model: Team.php

   public function organization()
    {
        return $this->belongsTo('App\Organization');
    }

Model: Organization.php 

  public function teams()
    {
        return $this->hasMany('App\Team', 'owner_id');
    }
Aug
19
2 months ago
Activity icon

Replied to Refactor Blade Code Into Vue Code

Vue component code:

<template>
<div>
    <h2 style="text-align: center">User invitation</h2>
        <div class="container">
            <div class="card card-default">
                <div class="card-header">User Invitation </div>
                <div class="alert alert-danger" v-if="errors.length">
                    <b>Please correct the following error(s):</b>
                    <ul>
                        <li v-for="error in errors">{{ error }}</li>
                    </ul>
                </div>
                <div class="card-body">
                    <form @submit.prevent="inviteUser">
                        <div class="form-group">
                            <label>Assigned user</label>
                            <select class="form-control" v-model="invitee.usermail">
                                <option value="">-</option>
                                <option v-for="user in users"  v-bind:value="user.email">{{ user.name }}</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>Organization</label>
                            <select class="form-control" v-model="invitee.organization">
                                <option value="">-</option>
                                <option v-for="organization in organizations"  v-bind:value="organization.name">{{ organization.name }}</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>Assigned team</label>
                            <select class="form-control" v-model="invitee.team">
                                <option value="">-</option>
                                <div v-for="organization in organizations"
                                :organization="organization">
                                     <option v-for="team in organization.teams" v-bind:value="team.name">{{team.name}}</option>
                                </div>
                            </select>
                        </div>
                            <button type="submit" class="btn btn-success">Invite user</button>
                        </form>
                </div>
            </div>
        </div>


</div>
</template>

<script>
export default
{
    data()
    {
        return {
            errors: [],
            organizations: {},
            users: {},
            invitee: {},
        }
    },
    mounted(){
        this.getUsers()
    },
    methods:{
        validateInvite(){
            if(this.invitee.organization == '') this.errors.push("Please assign organization")
            if(this.invitee.usermail == '') this.errors.push("Please assign usermail")
            if(this.invitee.team == '') this.errors.push("Please assign team")
            return this.errors;
        },
        getUsers() {
                this.axios
                    .get('http://local.requestmapper.com/api/invitee')
                    .then(response => {
                        this.users = response.data.users
                        this.organizations = response.data.organizations
                        //this.teams = response.data.organizations.teams
                    })
                    .catch(error => console.log(error))
                    .finally(() => this.loading = false)
        }
</script>
Activity icon

Replied to Refactor Blade Code Into Vue Code

Yeah, I get proper response what i expecting but when i use your earlier v-for approach, still doesn't show anything. According to the idea, it should work fine

Activity icon

Replied to Refactor Blade Code Into Vue Code

I can't select any teams, it returns normal response. Ok, for making picture clear, I can post my controller code how i get data

public function invitees(){
      $users = User::all()->except(Auth::user()->id);

        $organizations = Organization::all();


        $teams = Team::all();

        return response()->json(['users' => $users,
            'organizations' => $organizations,
            'teams' => $teams], 200);
}
Activity icon

Replied to Refactor Blade Code Into Vue Code

Because i want fetch teams which belongs to certain organization. My all front-end use Vue. Organizations can have many teams. @ravish I tried to do your approach doesn't work.

Activity icon

Started a new Conversation Refactor Blade Code Into Vue Code

Hello. I face with one issue. How refactor this view blade code into vue

@foreach ($organizations as $organization)
@foreach($organization->teams as $team)
{{$team->name}}
@endforeach
@endforeach