Capper33

Capper33

Project Manager at Serial Experiments Emerging Technologies LLP

Member Since 4 Years Ago

Hyderabad, India

Experience Points
20,630
Total
Experience

4,370 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
253
Lessons
Completed
Best Reply Awards
5
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 5
20,630 XP
Feb
19
2 days ago
Activity icon

Awarded Best Reply on How Can I Count From Model ?

I think this should work

$stock->activities()->count();
Activity icon

Replied to How Can I Count From Model ?

I think this should work

$stock->activities()->count();
Activity icon

Replied to What Is The Best Way To Use Same Form For Create And Edit Blade Template In Laravel 6?

I use vue to make the input elements components which take old_input as optional components. Form action can change according to the requested route.

Feb
16
5 days ago
Activity icon

Awarded Best Reply on View Not Found Shared Hosting

@haritz Check your controller code where you are returning the view

it should be like

return view('league.some_blade_file_name')
Feb
15
6 days ago
Activity icon

Replied to View Not Found Shared Hosting

@haritz Check your controller code where you are returning the view

it should be like

return view('league.some_blade_file_name')
Activity icon

Replied to Laravel Check Record If Exist Throw Exception

mistake in my code

if ($schedule->exists())

should be

if($existing_schedule)

if the combination of teacher, subject, room, start time, end time and day is not in data base, it will get saved as a new schedule. Otherwise it will dd('Exist')

Also put a return statement after $schedule->save();

Activity icon

Replied to Laravel Check Record If Exist Throw Exception

@vincentsanity

I'm assuming a Schedule is defined uniquely by Teacher , subject, room and start time.

So, you need to check if there exists a Schedule in our database with the same combination of values.

So you do this

$existing_schedule = Schedule::where('teacher', $request->teacher)
->where('subject_code_id', $request->subject)
->where('room_id', $request->room)
->where('start_time', $request->start_time)
->first();

if ($existing_schedule->exists()) {
    dd('Exist');
} else {
    $schedule->subject_code_id = $request->subject;
        $schedule->teacher_id = $request->teacher;
        $schedule->room_id = $request->room;
        $schedule->start_time = $request->start_time;
        $schedule->end_time = $request->end_time;
        $schedule->school_year = $request->schoolyr;
        $schedule->semester = $request->sem;
        $schedule->term = $request->term;
        $schedule->day = $request->days;
    $schedule->save();
}

Hope this is what you are looking for.

Activity icon

Replied to Laravel Check Record If Exist Throw Exception

@vincentsanity Please check what @scooby said a few minutes ago. That is correct.

But, you first need to get $id. Hope you are sending in request.

is $id == $request->id I mean are you sending the schedule's ID in the request?

If yes, do what @scooby said

$id = $request->id;
$schedule = Schedule::find($id);

if ($schedule->exists()) {
    throw new Exception('Record exists');
} else {
    $schedule->create($request->validate([
        'subject' => 'required',
        ...
    ]);
}
Activity icon

Replied to Children, Children, Parents.

You can use Vue js for this kind of reactivity. Or.. React / Angular.

Activity icon

Awarded Best Reply on App\Http\Controllers\Spatie\PdfToImage\Pdf' Not Found

Add this at the top of your controller:

use Spatie\PdfToImage\Pdf;

and

$pdf = new Pdf($files)
Activity icon

Replied to App\Http\Controllers\Spatie\PdfToImage\Pdf' Not Found

Did you change this line:

$pdf = new Pdf($files)
Activity icon

Replied to App\Http\Controllers\Spatie\PdfToImage\Pdf' Not Found

Add this at the top of your controller:

use Spatie\PdfToImage\Pdf;

and

$pdf = new Pdf($files)
Feb
14
1 week ago
Activity icon

Replied to Laracasts Quizzes

On question 3, I couldn't see the option Route Model Binding. Was perplexed and chose something else to continue the test.

Activity icon

Replied to How To Get Old Value On Select Option ?

I think your code should work. If not, try this from

https://laracasts.com/discuss/channels/laravel/how-to-show-old-data-of-select-element-in-laravel

<option value="{{ $id }}" @if(old('user_id') == $id) selected @endif>{{ $nama_unit }}</option>
Activity icon

Replied to Jquery Click Events Issue

Unable to understand what is needed here. From your code, clicking on a will insert a text input into it.

If you have 10 td tags and you clicked on 6 of them you will be seeing 6 inputs.

What do you want the application to do? a) Do not allow user to click anywhere else while the first input is not filled? b) remove input in first td, and generate new one in the next ?

Jan
16
1 month ago
Activity icon

Replied to Export PDF Get Error ''Too Few Arguments To Function App\Http\Controllers\AdminController::getPDF(), 0 Passed And Exactly 1 Expected''

getPDF method is expecting a $journal object. You are not passing it either in the blade file or the route. You can use Route Model binding for this.

in blade file:

<a href="/getPDF/{{$journal->id}}" class="btn btn-primary" target="_blank">CETAK PDF</a>

In route:

Route::get('getPDF/{journal}', '[email protected]')->name('getPDF');

In controller:

public function getPDF(Aduan $journal)

Don't forget to "use" the model Aduan in controller.

Having said this, looks like there are quite a few gotchas in your code. I cannot understand the language. Can't help completely. Example: $journals is a paginate object. Need to figure out how to get the id of each in your blade file.

Hope this helps.

Cheers

Dec
28
1 month ago
Activity icon

Replied to Help Me Understand Rate Limiting

So, if there's an authenticated user, its based on the number of requests from the user. If no user, its based on ip.

@siangboon thanks for pointing me in the right direction.

Dec
26
1 month ago
Activity icon

Started a new Conversation Help Me Understand Rate Limiting

Is the rate limiting based on logged in user account?

Or is it based on the ip address from which requests are coming.

Activity icon

Replied to How To Migrate Entire Laravel Project To AWS? Up And Running

Depends on which AWS EC2 instance AMI you use : AWS LInux, AWS Linux 2, Ubuntu, others? Depending on the AMI the setup instructions will vary. I use AWS LInux 2. This Medium post helped me:

https://medium.com/@hbayraktar/how-to-install-laravel-5-on-amazon-linux-2-303ef2d38fa4

After the environment is setup, you can copy your application code. No need to copy vendor and node modules folder.

After copying the application, you can run the commands like:

composer install,

php artisan key:generate,

npm install,

npm run dev,

Setup the db credentials in .env etc..

There is no need to run php artisan serve. If you follow the instructions in link above, apache will be serving the website.

Dec
05
2 months ago
Activity icon

Commented on Inheritance

Thank you.

Activity icon

Awarded Best Reply on Laravel Pusher

Now that I see the full HTML code, I can help you better.

When we call specific_div.empty(), entire form will be destroyed. After that we are only generating the hidden input and a couple of spans. So the form will not work.

In your code, I see that we have elements with id and classes. Please add id tag for letter and number. id="letter" id="number"

Modify code in the bind function to this:

$("#call_id").val(data.id);
$("#letter").html(data.letter);
$("#number").html(`Number: ${data.Number}`);

Please spend some time on the essentials of Javascript DOM management and JQuery. It will help you a lot.

Dec
04
2 months ago
Activity icon

Commented on Inheritance

At 5:30, "is a" relationship was checked by inserting a the comment at line #28. I did not understand this. How are we checking whether the relationship exists by inserting a comment? Does the editor highlight something when we insert the comment?

Activity icon

Replied to Laravel Pusher

Now that I see the full HTML code, I can help you better.

When we call specific_div.empty(), entire form will be destroyed. After that we are only generating the hidden input and a couple of spans. So the form will not work.

In your code, I see that we have elements with id and classes. Please add id tag for letter and number. id="letter" id="number"

Modify code in the bind function to this:

$("#call_id").val(data.id);
$("#letter").html(data.letter);
$("#number").html(`Number: ${data.Number}`);

Please spend some time on the essentials of Javascript DOM management and JQuery. It will help you a lot.

Dec
03
2 months ago
Activity icon

Replied to Laravel Pusher

If there is only one div in the page like you said <div id="new_call>, then we can define the specific div as:

const specific_div = $(`#new_call`);

If you have many divs showing all the calls and you need to modify a specific one, you will need to use the data.id in the identity of every div. That will allow for selecting that div when we get data from pusher. But, please note: the above method of selecting and updating specific div will work only if you have Jquery. Otherwise, you will have to use pure javascript, or any framework which may already be installed.

About the second part of your question: Yes. You can use any sort of html and append it to specific div.

I suggest you go through javascript DOM management / JQuery. Here is a w3schools link: https://www.w3schools.com/jquery/default.asp

Activity icon

Replied to "404 Not Found" When Submitting Subscription Form

Please show the blade file content for the form. Maybe there is a typo in your form's action.

Activity icon

Replied to Laravel Pusher

Assuming that the specific div is identified with the id coming in the data. So, if data.id = 3, assuming that the specific div has id="call_3".

If you are using jQuery this code should work:

var channel = pusher.subscribe('my-channel');
        channel.bind('my-event', function(data) {
            const html = `<p>Letter: ${data.letter}</p><p>Number: ${data.Number}</p>`;
            const specific_div = $(`#call_${data.id}`);
            // Empty the div
            specific_div.empty();
            // Populate new html
            specific_div.append(html);

    });
Dec
01
2 months ago
Activity icon

Replied to SPA Laravel And Vue.

@mrchenova ,

If not browser's local storage, you can store it in memory -> VueX Store. The problem with this approach is, if we click reload in browser, the vue application reloads and loses the Access token. So, will need to login every time browser reload button is used.

Nov
30
2 months ago
Activity icon

Replied to Undefined Variable Laravel

Hi @noel ,

I had a similar issue with compact recently. Replaced compact with associative array of data and it worked.

return view('dashboards.student-dashboard', ['id' => $id, 'courses' => $courses, 'posts' => $posts]);

Please let me know if this works for you. Need to investigate why compact does not work.

Activity icon

Replied to How To Correctly Get Props In Vue Component

Hi @adamr,

Guess my message was not easy to understand. Sorry for not being clear. Anyways, glad that you got it working.

Looking at your code, "props: ['work']" in work.vue can be removed because it is not being used. Props are used to send data to the component from the parent which is calling the component. Here parent = home.blade.php, component = work.vue

For example, if we want to set the work-items card-header from home.blade, we'd do this: home.blade.php

@extends('layouts.app')

@section('content')
    <work-items :myTitle="My Card Title"></work-items>
@endsection 

work.vue

<template>
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ myTitle }}</div>
                <div class="card-body">
    <ol><li v-for="item in taskList">{{ item.text }}</li></ol>
                </div>  
            </div>  
        </div>  
    </div>  
</div>  

</template>

<script>
    export default {
        name: 'work-items',
        props: ['myTitle'],
    data: function() {
        return {
        taskList: [
              { id: 0, text: "go gym" },
              { id: 1, text: "go work" },
              { id: 2, text: "go eat" },
              { id: 3, text: "go play" },
            ]
        }
    },
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

Following the same logic, if the laravel controller is sending taskList to home.blade.php, you could send it to work-items as a prop. Hope this helps.

Activity icon

Replied to How To Check Attributes In Policy Create Method?

HI @thiagobit, Here's my attempt at the 'create' method in KeyResultPolicy:

public function create(User $user, Objective $objective) {
        $objectiveOwner = $objective->user;
        // If user is owner/ creator of objective
        if ($user->id === $objectiveOwner->id) {
            return true;
        }
        // Owner and user are different people but from same company
        if ($user->company === $objectiveOwner->company) {
            return true;
        }

        return false;
    }

Hope it helps. This code assumes that the corresponding model methods are already set and company is just a string attribute of user. Need to pass the objective instance to the policy method. Let me know if it works.

Cheers.

Activity icon

Replied to SPA Laravel And Vue.

Jeffrey Way's got this series to help : Laravel, Vue and SPAs. 90 minutes to get you started. https://laracasts.com/series/laravel-vue-and-spas

Passport seems a robust solution with Access token lifecycle management. I have built a couple of SPAs in Vue with Laravel backend. Implemented with Password Grant Client from Passport

How it works:

  1. Follow documentation (https://laravel.com/docs/5.8/passport) and generate password grant client
  2. Login Page in Vue will post email id and password to an API route which authenticates the user and returns access_token.
  3. Store access_token in Vuex store, or LocalStorage of browser
  4. Use the access token in Authorisation header in all axios requests

Here is a gist which will help you in setting the api route: https://gist.github.com/vishy-experiments/217441363b1271d3e1647585a0f9405b

axios example with access_token in local storage:

axios .post(url, data, {
          headers: {
            Authorization: `Bearer ${localStorage.getItem("access_token")}`
          }
        })
        .then(response => {
          console.log(response.data);
        })
        .catch(error => {
          this.handleError(error);
        });

Nov
29
2 months ago
Activity icon

Replied to Need Help, Password Protect A Page Or Resource Route

I think a Policy is a good option here.

In Policy:

public function view (User $user, MyModel $myModel, $request) {
        if ($myModel->privacy === 0) {
            return true;
        }

        // Checking for model's password in session
        // Assuming that model password key in session is stored as 'myModelPaa_modelID'
        $model_key = 'myModelPass_' . $myModel->id;

        // Assuming model meta data is accessed via a hasOne relationship
        $modelMeta = $myModel->modelMeta;

        if ($request->session()->exists($model_key) && session($model_key) === $modelMeta->password) {
            return true;
        }

        return false;

    }

in Controller method

if ( $user->can('view', $myModel) ) {
        // 
 } else {
        // Redirect to password input page where myModelPaa_modelID will be set in session
 }
            

Not sure if we need to pass $request to policy. Please let me know if this works.

Activity icon

Awarded Best Reply on How To Correctly Get Props In Vue Component

Todo.vue has data with key trackList which is not used anywhere. The data in the component is scoped within it. It will not be accessible anywhere else in the parent (home.blade.php).

To render trackList, you will need to put in a v-for iterating over trackList within Todo.vue

Nov
28
2 months ago
Activity icon

Replied to How To Correctly Get Props In Vue Component

Todo.vue has data with key trackList which is not used anywhere. The data in the component is scoped within it. It will not be accessible anywhere else in the parent (home.blade.php).

To render trackList, you will need to put in a v-for iterating over trackList within Todo.vue