Yorki

Yorki

Member Since 1 Year Ago

Experience Points 44,100
Experience Level 9

900 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 1
Lessons
Completed
Best Reply Awards 70
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.

10 Oct
11 months ago

Yorki left a reply on Repository Best Practice: Pass Object Id Or Object(model Instance) As Repository Functions' Parameter?

Personally I use Ids. If you want to use models you should remember to sychronize them too by setting their attributes each time you update data by repository. Also having models as function param for me is more like wrapper since you will have to use model setters and save method anyway.

08 Oct
11 months ago

Yorki left a reply on Migrating Laravel From One Computer To Another One [ISSUE]

You will need to export your entire database to sql file by mysqldump command https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html

mysqldump -u [username] -p [databaseName] > file.sql

Then you will import it by something like

mysql -u [username] -p [databaseName] < file.sql

Yorki left a reply on PHP How To Create Urls Properly?

Native PHP function http_build_query which you can find documentation there http://php.net/manual/en/function.http-build-query.php

Also parse_url will be useful for you http://php.net/manual/en/function.parse-url.php

04 Oct
11 months ago

Yorki left a reply on Recover The Deleted Data

There is no way to recover this data unless you had backup of your database.

Yorki left a reply on Updating Value

Good to hear

Yorki left a reply on Updating Value

Is your project model class name Projects?

Yorki left a reply on Updating Value

What about projects model and projects relation on company model?

Yorki left a reply on Updating Value

Can you show code of your projects model? Does it exists? You should have named it in camelcase and singular like Project.

Also show me your C:\xampp\htdocs\crud\resources\views\companies\show.blade.php

Yorki left a reply on Laravel Homestead On A Custom VM

Do you use Vagrantfile? This should be enough to run it

Vagrant.configure('2') do |config|
    ...

    config.vm.provision :shell, path: 'after.sh', run: 'always'
end

Yorki left a reply on Redirect Admin To Admin View And Normal User To User View

In LoginController you could do something like this

/**
 * @return string
 */
public function redirectPath()
{
    if (Auth::user()->isAdmin) {
        return route('admin.index');
    }

    return $this->redirectTo;
}

Yorki left a reply on Updating Value

You have typo upate instead of update.

28 Sep
11 months ago

Yorki left a reply on Fillable Attributes - Allowed In One Action, Forbidden In Some Other

You can also do this with mass assignment

User::create(array_merge(request()->all(), ['is_admin' => 0]));

Yorki left a reply on Fillable Attributes - Allowed In One Action, Forbidden In Some Other

You could set this field default value to 0 in migration. Or override register method

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => Hash::make($data['password']),
        'is_admin' => 0,
    ]);
}

Yorki left a reply on How To Display Table Row Records Acording To Its Depending Values?

@aurawindsurfing You still don't get what he wanted to accomplish :)

First we need to sort collection by adtype desceding. Well thats pretty easy.

Now you have to sort:

  • adtype=1 - desceding by updated_at
  • adtype=0 - desceding by created_at

Now you got it? Second sort rule is dependant on value of adtype.

Yorki left a reply on How To Display Table Row Records Acording To Its Depending Values?

@aurawindsurfing I meant you can't sort it easy way (without callback) having dependency on first sort result :)

Yorki left a reply on Submit Button Not Working Inside Form Tag

What about changing it to type submit?

 <input type="submit" value="Submit">

Yorki left a reply on Route Parameter Does Not Get Passed To Controller

public function test(Request $request, $item) 
{
    dd($item);
}

Yorki left a reply on When Going To Local Server For Laravel, I Get 500 Error Every Time

Latest laravel version installed via laravel new project does it automatically for you :)

Yorki left a reply on When Going To Local Server For Laravel, I Get 500 Error Every Time

Type php artisan key:generate into console.

Yorki left a reply on Wrong Slug Direct Access Laravel.

You don't need to do any check after findOrFail or firstOrFail call. Cause it does throw exception if not found.

$oProduct = Product::where('slug', $productSlug)->firstOrFail();

// we are good here, this product does exists
dd($oProduct);

Yorki left a reply on How To Display Table Row Records Acording To Its Depending Values?

@aurawindsurfing No it doesn't. Did you read his post? Based on first column value it sorts second by created_at or updated_at.

Yorki left a reply on How To Display Table Row Records Acording To Its Depending Values?

Maybe this helps? Not sure if correct order tho, but should give you an idea.

public function index()
{
    $vehicles = Vehicle::with('uploads')->get()->sort(function ($a, $b) {
        if ($a->adtype !== $b->adtype) {
            return $b->adtype - $a->adtype;
        }
    
        return $a->adtype
            ? ($a->updated_at->gt($b->updated_at) ? -1 : 1)
            : ($a->created_at->gt($b->created_at) ? -1 : 1);
    });
    
    return view('vehicles.index')->withVehicles($vehicles);
}

Yorki left a reply on I Want My Articles On The Front Page To Slide Down

Aren't asc order suitable for you? Or maybe just order by votes

$articles = Article::with(['user' => function ($query) {
        $query->withTrashed();
    }])
   ->with('categorie', 'comments', 'votes')
   ->withCount('votes')
   ->where('created_at', '<=', Carbon::now()->subHour(1))
   ->where('is_active', true)
   ->orderBy('id', 'ASC')
   ->paginate(25);

Yorki left a reply on Replacing An Empty Value With Text In JavaScript

I see, then you could go like this:

var policy = response.policyinfo;
var link1 = policy[2] 
    ? '<a href="' + policy[2] + '">Policy Wording </a>'
    : 'n/a';
var link2 = policy[3] 
    ? '<a href="' + policy[3] + '">Policy Wording </a>'
    : 'n/a';

$("#form-group").empty().append('<table><thead><tr><th>Name</th><th>Claims Telephone</th><th>Policy Wording</th><th>IPID</th></tr></thead><tbody><td>' + policy[0] + '</td> <td>' + policy[1] + '</td> <td>' + link1 + '</td><td>' + link2 + '</td></tr></tbody></table');

Yorki left a reply on Datatable Order

Lately questions on this forum are formulated as for diviner. We should all get the crystal balls.

Did you check their documentation and aren't options suitable for you?

columnDefs: [{ 
    orderable: false, 
    targets: [0] 
}, { 
    orderable: true, 
    targets: [5,12,13] 
}],

Yorki left a reply on Replacing An Empty Value With Text In JavaScript

Not sure what are you trying to achive and where, but I guess you are talking about policyinfo.

var policy = response.policyinfo;

$("#form-group").empty().append("<table><thead><tr><th>Name</th><th>Claims Telephone</th><th>Policy Wording</th><th>IPID</th></tr></thead><tbody><td>"
    + (policy[0] ? policy[0] : 'n/a') + "</td> <td>" 
    + (policy[1] ? policy[1] : 'n/a') + "</td> <td><a href=" 
    + policy[2] + ">Policy Wording </a></td><td><a href=" 
    + policy[3] + ">IPID </a></td></tr></tbody></table>");

Yorki left a reply on How To Store Id In Show Function In Laravel 5-4

First of all you need to start from show method of SchoolController and pass current school to view, something like:

public function show(School $school)
{
    return view('admin.school.show', [
        'school' => $school,
    ]);
}

I assume that requisition is relationship of school and cannot be standalone. So easiest way is just to pass school id into create method by link.

<a href="{{ route('requisitions.create', ['school_id' => $school->id]) }}">Create requisition for this school</a>

Now in create method of RequisitionController:

public function create(Request $request)
{
    $school = School::findOrFail($request->school_id);

    return view('Admin.requisitions.create', [
        'school' => $school
    ]);
}

And finally use this id in your create blade.

<form action="{{ route('requisitions.store')}}" method="post">
    {{ csrf_field() }}
    <input type="hidden" name="school_id" value="{{ $school->id }}" />
  
    ...
</form>

Then in your store method of RequisitionController:

public function store(Request $request)
{
    $requisition = new Requisition();
    $requisition->user_id = auth()->user()->id;
    $requisition->school_id = $request->input('school_id');
    $requisition->type = $request->application;
    $requisition->status = 0;
    $requisition->approved = 0;
    $requisition->save();

    return redirect(route('school.index'));
}

Yorki left a reply on How To Store Id In Show Function In Laravel 5-4

Show me your route of store.

Yorki left a reply on How To Execute 'LIKE' Raw Query With Binding?

Try this one

DB::table('users')
    ->where('name', 'like', '%' . $request->name . '%')
    ->get();

or

DB::select("SELECT * FROM `users` WHERE `name` LIKE ':name'", ['name' => '%' . $request->name . '%']);
27 Sep
11 months ago

Yorki left a reply on Laravel Markdown Support Like Laracast

You need to write your own parser or just check out this repo https://github.com/cebe/markdown

Yorki left a reply on How To Store Row Id In Laravvel

How is your controller supossed to know which school you want to use without declaring its id in qequisitions.store route?

24 Sep
11 months ago

Yorki left a reply on What Kind Of Magic Is $user['id' ]

Models does implements ArrayAccess interface. You can read more about it at http://php.net/manual/en/class.arrayaccess.php

Yorki left a reply on Need To Create A Service To Execute My Method Every Seconds

for ($i = 0; $i < 59; $i++) {
    exec('php path-to-your-app/artisan process:stock > /dev/null 2>&1 &');
    sleep(1); //or time_sleep_until
}

Yorki left a reply on Third Party API Headers

It all depends on API, check over github if there is any ready to use api client for your external service. If not then you have to write your own from scratch. You can take a look at mine https://github.com/Yorkii/laravel-payu. You will see how I did it and used with laravel service provider.

Yorki left a reply on Request Session() In Job (Exception: Call To Undefined Method Session())

@Jurrien You don't know what are you talking about. This is job method, not controller one. These are fired from consumers having no access to session.

Yorki left a reply on Request Session() In Job (Exception: Call To Undefined Method Session())

You should pass language while queueing job.

dispatch(new SendMailJob($request->session()->get('lang', 'en')));
public function __construct($lang)
{
    $this->lang = $lang;
}

public function handle()
{
    Mail::to($this->user->email)->locale($this->lang)->send(new HelloMail($this->user));
}

Yorki left a reply on Need To Create A Service To Execute My Method Every Seconds

I don't think that using PHP in that case is a good idea. You should go for persistent server application like nodejs or java. I mean you can go with PHP if you really want, but sooner or later you will realize that was wrong decision. However you could do cron job which spawn process each second to process your method.

Yorki left a reply on Need To Create A Service To Execute My Method Every Seconds

And why don't you queue job after receiving base rates from external service to check them?

Yorki left a reply on Third Party API Headers

Are you talking about outgoing API calls from your application to external API or incoming calls to your application API? If the second one then yes, you can make middleware and add to api group checking for obligatory fields and validating them.

If you application makes API calls to external API then you should make/use API client which handles this every request. Like:

public function getUsers()
{
    return $this->get('/users');
}

protected function get($endpoint)
{
    return $this->httpClient->get($this->getFullUrl($endpoint), [
        'headers' => $this->getHeaders(),
    ]);
}

protected function getHeaders()
{
    return [
        'Authorization' => 'Basic ' . $this->authHash,
        'X-Requested-With' => 'XMLHttpRequest',
    ];
}
21 Sep
11 months ago

Yorki left a reply on File Management

If you are using laravel then you should do it laravel way:

use Illuminate\Support\Facades\File;

...

if (!File::exists($dirPath)) {
    File::makeDirectory($dirPath, 0777, true);
}

// To check if its directory and not file
if (File::isDirectory($dirPath)) {
    ...
}

20 Sep
11 months ago

Yorki left a reply on Laravel Cron Jobs

Sounds like you are passing some argument after artisan schedule:run. Can you try with single gt sign

> /dev/null 2>&1

Yorki left a reply on Laravel Cron Jobs

Check exception log and try to run it manually from terminal the same way

php /path-to-your-project-2/artisan schedule:run

Yorki left a reply on Laravel Cron Jobs

Yes, all you need to do is another entry with project 2 path to artisan. You can have multiple cron jobs in crontab :)

* * * * * php /path-to-your-project-1/artisan schedule:run >> /dev/null 2>&1
* * * * * php /path-to-your-project-2/artisan schedule:run >> /dev/null 2>&1

Yorki left a reply on Show Results Where Boolean Is Equal To

Client::where('id', $id)->where('disabled_client', '0')->firstOrFail();

Yorki left a reply on Show Results Where Boolean Is Equal To

findOrFail does return query result, not query itself. Try this way

Client::where('id', $id)->where('disabled_client', '0')->first();
17 Sep
1 year ago

Yorki left a reply on Change Button Color After Ajax Request

You should not declare colors in your controller. This is up to frontend how to visualize data. Think of just passing whenever article was voted or not.

$voted = $user->votedFor($article);

if ($voted) {
    $user->unvoteFor($article);
} else {
    $user->voteFor($article)
}

return response()->json([
    'success' => true, 
    'count' => $article->fresh()->votes->count(), 
    'voted' => $voted,
]);

Then you should process this on front something like:

var color = response.voted
    ? 'black'
    : '#38c172';

Yorki left a reply on Update Inputs With Same Name Repeated

@petrir Paste stacktrace too.

Yorki left a reply on Update Inputs With Same Name Repeated

This is exactly what this code does. You have something wrong somewhere else. Where does error points to? File and line, paste it.

Yorki left a reply on Update Inputs With Same Name Repeated

@petrir Because of for loop. I've made it $device contains only one device per iteration so you get all attributes to update per device. You might check this by replacing dd with var_dump and die after for loop. You will see that loop is processing each device separately. Wasn't this your goal?