beginner_luck

Experience

940

0 Best Reply Awards

  • Member Since 1 Month Ago
  • 2 Lessons Completed
  • 0 Favorites

3rd May, 2018

beginner_luck started a new conversation How To Create A Link In Javascript With Laravel • 3 weeks ago

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.

1st May, 2018

beginner_luck left a reply on Showing The Image Of A Single Post. • 3 weeks ago

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

30th April, 2018

beginner_luck started a new conversation Showing The Image Of A Single Post. • 3 weeks ago

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) • 3 weeks ago

This problem was solved. I have just removed this.

contentType: false, processData: false,

27th April, 2018

beginner_luck left a reply on Laravel Edit Post With Ajax Call • 3 weeks ago

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 • 3 weeks ago

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 • 3 weeks ago

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');
                }

        });
    });

26th April, 2018

beginner_luck left a reply on Error When Editing Post • 4 weeks ago

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 • 4 weeks ago

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

beginner_luck left a reply on Error When Editing Post • 4 weeks ago

Okay Sir @Cronix will post my code here.

beginner_luck left a reply on Image Upload Using Laravel And Ajax. • 4 weeks ago

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 • 4 weeks ago

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 • 4 weeks ago

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

beginner_luck left a reply on Show Single Post In Laravel With Ajax Call • 4 weeks ago

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 • 4 weeks ago

Still the same @Sirik, nothing happens

beginner_luck left a reply on Show Single Post In Laravel With Ajax Call • 4 weeks ago

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 • 4 weeks ago

@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 • 4 weeks ago

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. • 4 weeks ago

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

25th April, 2018

beginner_luck left a reply on Image Upload Using Laravel And Ajax. • 4 weeks ago

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

beginner_luck left a reply on Image Upload Using Laravel And Ajax. • 4 weeks ago

@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. • 4 weeks ago

@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. • 4 weeks ago

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

beginner_luck left a reply on Ajax Call With Laravel Form • 4 weeks ago

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

beginner_luck left a reply on Image Upload Using Laravel And Ajax. • 4 weeks ago

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. • 4 weeks ago

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); 
            }


        });

    });

24th April, 2018

beginner_luck left a reply on Ajax Call With Laravel Form • 4 weeks ago

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. • 1 month ago

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.

19th April, 2018

beginner_luck left a reply on Ajax Call With Laravel Form • 1 month ago

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 • 1 month ago

Still not working but the validation error was gone.

beginner_luck left a reply on Ajax Call With Laravel Form • 1 month ago

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 • 1 month ago

Thank you @rin4ik I will update my code here.

beginner_luck left a reply on Ajax Call With Laravel Form • 1 month ago

@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 • 1 month ago

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

18th April, 2018

beginner_luck started a new conversation Ajax Call With Laravel Form • 1 month ago

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); 
            }


        });

    });

16th April, 2018

beginner_luck started a new conversation Count Number Of Posts In A Category In Vuejs • 1 month ago

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.

15th April, 2018

beginner_luck left a reply on Laravel To VueJs Limit Characters To Show • 1 month ago

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

12th April, 2018

beginner_luck started a new conversation VueJs • 1 month ago

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 ? "..." : "" }}

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.