beginner_luck

beginner_luck

Member Since 1 Year Ago

Experience Points 940
Experience Level 1

4,060 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 2
Lessons
Completed
Best Reply Awards 0
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.

03 May
1 year ago

beginner_luck started a new conversation How To Create A Link In Javascript With Laravel

can someone help me on how I can create a link in Javascript with Laravel. Or how can I convert this code to javascript?("{{ route('blog.single', $post->slug) }}") because I wanted to show the URL of every single post I have used in that code, I don't know what's wrong but the URL only shows me the last post that I have created, when everytime I click the VIEW button the one that keeps on showing is the slug/url in the last post I created.

This is my code for getting the slug in database

 data-slug="{{$post->slug}}"

This is my code in passing it using jQuery.

$(document).on('click', '.show-post', function() {

  var slug = $(this).attr('data-slug');
   $('#show-slug').html(slug);
   $('.show-single-post').css('display','block');
   $('.posts-table').css('display','none');

});

And my code for creating the URL.

{{ route('blog.single', $post->slug) }}

The blog.single, is my single.blade.php that shows the single post.

01 May
1 year ago

beginner_luck left a reply on Showing The Image Of A Single Post.

What do you mean on how I set my $post variable, sir @aurawindsurfing ?

30 Apr
1 year ago

beginner_luck started a new conversation Showing The Image Of A Single Post.

Hello did anyone knows how can I show the proper file image of the single post by the time I click View button because in my end the one that keeps on showing is the image of the last post that I added in the database?

This is my code for getting the data on the single post.

View

My Ajax code in passing the data of the single post.

    $(document).on('click', '.show-post', function() {

    var id = $(this).attr('data-id');
    var title = $(this).attr('data-title');
    var slug = $(this).attr('data-slug');
    var category = $(this).attr('data-category');
    var featured_image = $(this).attr('data-image');
    var body = $(this).attr('data-body');

    $('#show-title').html(title);
    $('#show-slug').html(slug);
    $('#show-category').html(category);
    $('#show-image').html(featured_image);
    $('#show-body').html(body);
    $('#show-id').html($(this).data('id'));


    $('.show-single-post').css('display','block');
    $('.posts-table').css('display','none');
    });

This is my code for view format for the single post.

            <h1 id="show-title"> {{ $post->title }} </h1>

            <p id="show-body" class="lead">{!! $post->body !!}</p>
        </div>
</div>

Do I need to provide a controller in my show single page?

beginner_luck left a reply on Error On Edit Post Shows 422 (Unprocessable Entity)

This problem was solved. I have just removed this.

contentType: false, processData: false,

27 Apr
1 year ago

beginner_luck left a reply on Laravel Edit Post With Ajax Call

I don't have any idea why that error where keeps on showing whereas, the field has already a data on it because I pass the data in the edit form when I try to save changes, that error keeps on showing.

beginner_luck left a reply on Laravel Edit Post With Ajax Call

Sir @Snapey this was the error shown in network request. {message: "The given data was invalid.",…} errors : {title: ["The title field is required."], slug: ["The slug field is required."],…} body : ["The body field is required."] category_id : ["The category id field is required."] slug : ["The slug field is required."] title : ["The title field is required."] message : "The given data was invalid."

beginner_luck started a new conversation Laravel Edit Post With Ajax Call

Can someone help me through this on what causes my code an error? An error shows me 422 (Unprocessable Entity) {message: "The given data was invalid.",…}.

//Ajax Code for edit post $(document).on('click', '.edit-post', function() {

        $('.edit-modal').css('display','block');
        $('.posts-table').css('display','none');


        var id = $(this).attr('data-id');
        var title = $(this).attr('data-title');
        var slug = $(this).attr('data-slug');
        var category = $(this).attr('data-category');
        var featured_image = $(this).attr('data-image');
        var body = $(this).attr('data-body');
    
        $('#edit-post-form #edit-title').val(title);
        $('#edit-post-form #edit-slug').val(slug);
        $('#edit-post-form #edit-category').val(category);
        //$('#edit-post-form #edit-image').val(featured_image);
        $('#edit-post-form #edit-body').val(body);
        $('#edit-id').val($(this).data('id'));


    });
    //Update New Post
    $("#update-post").click(function(e) {
        e.preventDefault();
         id = $('#edit-id').val();
        var title = $('#edit-post-form #edit-title').val();
        var slug = $('#edit-post-form #edit-slug').val();
        var category_id = $('#edit-post-form #edit-category').val();
        var featured_image = $('#edit-post-form #edit-image').val();
        var body = $('#edit-post-form #edit-body').val();


        $.ajax({
            type:'PUT',
            url: "/updatepost/" + id,
            headers: {
                'X-CSRF-TOKEN' : $('input[name="_token"]').val()
            },
            cache: false,
            contentType: false,
            processData: false,
            data: {
                title: title, 
                slug: slug, 
                category_id: category_id, 
                featured_image: featured_image, 
                body: body
            },
            success: function(data) {
                    toastr.success('Successfully Updated Post!', 'Success Alert', {timeOut: 5000});
                    $('#'+ id).html("<tr id='" + data.id + "' class='item'><th>" + data.id + "</th><td>" + data.title + "</td><td>" + data.body + "</td><td>" + data.created_at + "</td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-title='" + data.title + "' data-slug='" + data.slug + "' data-category='" + data.category_id + "' data-image='" + data.featured_image + "' data-body='" + data.body + "'><span class='glyphicon glyphicon-edit'></span> Edit</button></td></tr>");
                    $('.edit-modal').css('display','none');
                    $('.posts-table').css('display','block');
                }

        });
    });
26 Apr
1 year ago

beginner_luck left a reply on Error When Editing Post

I got new error sir @Cronix , it says (Unprocessable Entity). The given data was invalid errors : {title: ["The title field is required."], slug: ["The slug field is required."],…} body : ["The body field is required."] category_id : ["The category id field is required."] slug : ["The slug field is required."] title : ["The title field is required."] message : "The given data was invalid."

beginner_luck left a reply on Error When Editing Post

Sir @Cronix is this the only line that I need to remove?

beginner_luck left a reply on Error When Editing Post

Okay Sir @Cronix will post my code here.

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

Hello Sir @biishmar Can you help me with this error, please?

Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.

This error shows when I try to edit my post, and it seems like it comes with the image. Thank you sir.

beginner_luck started a new conversation Error When Editing Post

Can someone help me, because when I try to edit my post this error will comes out when I hit save.

Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.

beginner_luck left a reply on Show Single Post In Laravel With Ajax Call

Thank you very much @Snapey, it is now working.

beginner_luck left a reply on Show Single Post In Laravel With Ajax Call

Whenever I clicked the View button in a different post, the one that will show me in a single post is the last post that I have been added.

beginner_luck left a reply on Show Single Post In Laravel With Ajax Call

Still the same @Sirik, nothing happens

beginner_luck left a reply on Show Single Post In Laravel With Ajax Call

Sir, @Snapey No console errors are shown.

Yes, if I console.log the variables the value is being set according to what I expected. But in the page, wrong data will be shown.

beginner_luck left a reply on Show Single Post In Laravel With Ajax Call

@Snapey sorry, I just update my post. I didn't use ajax for this one.

beginner_luck started a new conversation Show Single Post In Laravel With Ajax Call

Hello can someone help me through this, I want to show the data of my single post, let say I have a list of post and there was a button on it as "VIEW", when I click the button the single post will then show and hide the table/list of post.

View Button:

View

the data will show in this button, but when I click the VIEW button, it showed me a wrong data in the single post.

My ajax Code: $(document).on('click', '.show-post', function() {

        var id = $(this).attr('data-id');
        var title = $(this).attr('data-title');
        var slug = $(this).attr('data-slug');
        var category = $(this).attr('data-category');
        var featured_image = $(this).attr('data-image');
        var body = $(this).attr('data-body');
    
        $('#show-title').val(title);
        $('#show-slug').val(slug);
        $('#show-category').val(category);
        $('#show-image').val(featured_image);
        $('#show-body').val(body);
        $('#show-id').val($(this).data('id'));

        $('.show-single-post').css('display','block');
        $('.posts-table').css('display','none');
    });

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

Yes sir @MarkLL that was the thing that I have been using. Thank you.

25 Apr
1 year ago

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

@biishmar yes sir, in the table of the same page.

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

@biishmar in my edit a post using ajax, do I also need to add the thing that you have says to me? This one. cache: false, contentType: false, processData: false,

use this in ajax option and create form data object and append all value into form data.

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

@biishmar how could I transform this code

View

and put this one on my success method

success: function(data) { toastr.success('Successfully Updated Post!', 'Success Alert', {timeOut: 5000}); $('.edit-modal').css('display','none'); $('.posts-table').css('display','block'); $('.item' + data.id).html("" + data.id + "" + data.title + "" + data.body + "" + data.created_at + " Edit"); }

the success method works but when it was being inserted in the table and when I try to click the button view, it doesn't work, I will just need to reload the page inorder the button View will work.

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

@biishmar If you don't mind, can I ask you one last question?

beginner_luck left a reply on Ajax Call With Laravel Form

Thank you for your help guys, @jlrdw @rin4ik @Snapey @ekhlas

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

Oh, Thank you very much @biishmar it is now working, I can upload an image now.

beginner_luck left a reply on Image Upload Using Laravel And Ajax.

Hello @biishmar is this right?

    $('#submit-post').click(function(e) {
        e.preventDefault();
        var title = $("#form-post").find("input[name='title']").val();
        var slug = $("#form-post").find("input[name='slug']").val();
        var category_id = $("#add-category").val();
        var featured_image = $("#add-image")[0].files[0];
        var body = $("#add-body").val();
        new form = new FormData();
        form.append('title', title);
        form.append('slug', slug);
        form.append('category_id', category_id);
        form.append('featured_image', featured_image);
        form.append('body', body);


        $.ajax({
            type : 'POST',
            url : "/addpost",
            headers: {
                'X-CSRF-TOKEN' : $('input[name="_token"]').val()
            },
            cache: false,
            contentType: false,
            processData: false,
            data : form,
            success: function(data){
                toastr.success('Successfully Added Post!', 'Success Alert', {timeOut: 4000});
                $('.create-form').css('display','none');
                $('.posts-table').css('display','block');
                $('.table tbody').append("<tr id='" + data.id + "' class='item'><th>" + data.id + "</th><td>" + data.title + "</td><td>" + data.body + "</td><td>" + data.created_at + "</td><td><button class='btn btn-outline-primary link-button' data-href='{{URL::to('posts/{$id}')}}'>View</button><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-title='" + data.title + "' data-slug='" + data.slug + "' data-category='" + data.category_id + "' data-image='" + data.featured_image + "' data-body='" + data.body + "'><span class='glyphicon glyphicon-edit'></span> Edit</button></td></tr>");
                console.log(data); 
            }


        });

    });
24 Apr
1 year ago

beginner_luck left a reply on Ajax Call With Laravel Form

Is there any other way on how I can include an image upload field and works using laravel and ajax,it seems like my problem was in my image upload, because when I don't put an image it is working perfectly, but when i put it doesn't.

beginner_luck started a new conversation Image Upload Using Laravel And Ajax.

Hello, can someone help me on how to include in the form a field for image upload using laravel and ajax? Thank you in advance.

19 Apr
1 year ago

beginner_luck left a reply on Ajax Call With Laravel Form

When I try to put a data in the form without putting an image on it, my data will saved in the database and it is working. I think my problem here is my image upload field.

beginner_luck left a reply on Ajax Call With Laravel Form

Still not working but the validation error was gone.

beginner_luck left a reply on Ajax Call With Laravel Form

Yes sir @rin4ik. Error Shown in Console.

POST http://blog.com/addpost 422 (Unprocessable Entity) POST http://blog.com/addpost 500 (Internal Server Error)

And in my network.

{message: "The given data was invalid.",…} errors

{featured_image: ["The featured image must be an image."]} featured_image

["The featured image must be an image."] 0

"The featured image must be an image." message

"The given data was invalid."

beginner_luck left a reply on Ajax Call With Laravel Form

Thank you @rin4ik I will update my code here.

beginner_luck left a reply on Ajax Call With Laravel Form

@Snapey this error will shows me

Error:

Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)

beginner_luck left a reply on Ajax Call With Laravel Form

Thank you, I am done replacing it. But my submit button still not working.

18 Apr
1 year ago

beginner_luck started a new conversation Ajax Call With Laravel Form

Hello can someone help me because I wanted to use ajax in my laravel form, when everytime I hit 'CREATE POST' button, the table contains all my post will hide and then the form will show, and when clicking the submit button the table will then show with its new data and the form will hide. I have a code but it is not working.

Form Code:

Create New Post

        {!! Form::open(['id' => 'form-post', 'method' => 'POST', 'action' => '[email protected]', 'data-parsley-validate' => '', 'files' => true]) !!}
            

            <div class="form-group">
                <label class="control-label" for="title">Title:</label>
                <input type="text" name="title" class="form-control" data-error="Please enter title." required />
                <div class="help-block with-errors"></div>
            </div>
            
            <div class="form-group">
                <label class="control-label" for="title">Slug:</label>
                <input type="text" name="slug" class="form-control" data-error="Please enter title." required />
                <div class="help-block with-errors"></div>
            </div>


            {{ Form::label('category_id', 'Category') }}
            <select id="add-category" class="form-control" name="category_id">
                    @foreach($categories as $category)
                        <option value='{{ $category->id }}'>{{ $category->name }}</option>
                    @endforeach 
            </select>

           {{ Form::label('featured_image', 'Upload Featured Image:', ['class' => 'form-spacing-top']) }}
           {{ Form::file('featured_image',["id" => 'add-image', "class" => 'form-control-file']) }}

          
          {{ Form::label('body', 'Post Body:') }}
          {{ Form::textarea('body', null, array('id' => 'add-body', 'class' => 'form-control')) }}


          {{ Form::submit('Create Post', array('id' => 'submit-post', 'class' => 'btn btn-success btn-lg btn-block', 'style' => 'margin-top: 20px;'))}}
        {!! Form::close() !!}

    </div>
</div>

Ajax Code:

    $(document).on('click', '.create-post', function() {
        $('.create-form').css('display','block');
        $('.posts-table').css('display','none');
    });

    $('body').on('click', '#submit-post', function(e) {
        e.preventDefault();
        var action = $('#form-post').attr('action');
        var title = $("#form-post").find("input[name='title']").val();
        var slug = $("#form-post").find("input[name='slug']").val();
        var category = $("#add-category").val();
        var featured_image = $("#add-image").val();
        var body = $("#add-body").val();
       
        $.ajax({
            type : 'POST',
            url : action,
            data : {
                title: title, 
                slug: slug, 
                category: category, 
                featured_image: featured_image, 
                body: body
            },
            dataType    : 'json',
            success: function(data){
                $('.create-form').css('display','none');
                $('.posts-table').css('display','block');
                $('.table tbody').append("<tr id='" + data.id + "' class='item'><th>" + data.id + "</th><td>" + data.name + "</td><td>0</td><td><button class='show-modal btn btn-success' data-id='" + data.id + "' data-title='" + data.title + "' data-slug='" + data.slug + "' data-category='" + data.category + "' data-image='" + data.image + "' data-body='" + data.body + "'><span class='glyphicon glyphicon-eye-open'></span> Show</button><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-title='" + data.title + "' data-slug='" + data.slug + "' data-category='" + data.category + "' data-image='" + data.image + "' data-body='" + data.body + "'><span class='glyphicon glyphicon-edit'></span> Edit</button><button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-title='" + data.title + "' data-slug='" + data.slug + "' data-category='" + data.category + "' data-image='" + data.image + "' data-body='" + data.body + "'><span class='glyphicon glyphicon-trash'></span> Delete</button></td></tr>");
                console.log(data); 
            }


        });

    });
16 Apr
1 year ago

beginner_luck started a new conversation Count Number Of Posts In A Category In Vuejs

Hi, can someone help me on how I can count the number posts in a specific category? Because I wanted to show the list of categories with their specific number of posts, let's say List of Categories: Daily post (2) Monthly post (5) Yearly post (0) Thanks in advance.

15 Apr
1 year ago

beginner_luck left a reply on Laravel To VueJs Limit Characters To Show

Thank you Sir @spekkionu and especially to you Sir @wilk_randall, this helps me solved the issue.

12 Apr
1 year ago

beginner_luck started a new conversation VueJs

Can someone help me, I have a blog and in my post.body I want to only show 300 characters and add Read More on it, in Vuejs. I have a working code but it seems that it will not work in VueJs, can someone help me on this? This is my code

{{ substr(strip_tags(post.body), 0, 300) }}{{ strlen(strip_tags(post.body)) > 300 ? "..." : "" }}