pickab00

Experience

1,370

0 Best Reply Awards

  • Member Since 1 Month Ago
  • 1 Lesson Completed
  • 0 Favorites

13th January, 2018

pickab00 left a reply on Use Slug To Display Post Category • 5 days ago

Thanks @numberone checked that link a while ago and solved the issue.

@Snapey what i wanted was to use the slug from category table to display every listing related to that category. Model binding helped me. I was once stuck at the point where getRouteKeyName() was not working. Until i found out that the getRouteKeyName does not work with findOrFail(). So i used where clause. Just pointing that out for anyone who come across this issue with binding

pickab00 started a new conversation Use Slug To Display Post Category • 5 days ago

Sorry if this seems like a broad question but here is the issue.

I have a route like so.

/listings/{slug}/{uuid}

Here is the blades link

This works with no issues. So the output link is something like this. /listings/room_for_rent/randomUUID

The problem is with the other function in my controller. I want the route "/listings/{slug}" to dislpay the category page but the url with the slug like this "/listings/room_for_rent".

Here is the controller:

    //Category listing page for listings
    public function listing_category_page($listingcategory_id){

        $show_listing_category = Listing::with('category', 'user')->where('verified', '=', '1')->where('listingcategory_id', $listingcategory_id)->latest()->paginate(10);


        $show_listing_category_detail = ListingCategory::findOrFail($listingcategory_id);


        return view('/front-end/category-pages/show_listing_category', compact('show_listing_category', 'show_listing_category_detail'));

    }

So in my table "listing" has listingcategory_id column. I am currently taking that value to display the URL so it comes like /listings/2 and not slug.

The slug is in my other table which is the "listing_categories" table. That table contains the slug column. The above mentioned route is taking the slug from that table.

My question is, how can i do the same to display listings using slug for that category instead of using the listingcategory_id column. Do i have to create a slug for listing table too? I am taking the slug from listing_categories table and i want the route to change to /listings/{slug} not /listings/{listingcategory_id}. With the current code posted above, i dont know how to achieve this because the slug is in another table which is related to listings table.

Here is my route:

Route::get('/listings/{listingcategory_id}/', 'FrontEnd\[email protected]_category_page')->name('listing.single.category.page');

Thanks

12th January, 2018

pickab00 left a reply on Trying To Get Property Of Non-object • 6 days ago

@lessan Ok i think i got it to work. I want to know if i am doing this right.

So i changed

public function post_single_page($postcategory_id, $id){

        $show_post = Post::where('postcategory_id', $postcategory_id)->where('id', $id)->first();

        return view('/front-end/show_post_single', compact('show_post'));

    }

To

public function post_single_page($postcategory_id, $id){

        $show_post = Post::findOrFail($id);

        return view('/front-end/show_post_single', compact('show_post'));

    }

and it works. even if i change the postcategory_id, it still shows the post and no error. I want to know if this is right way and if it is safe. It gives me 404 when i change the id now. i guess that's what i wanted.

one more thing. If i wanted to change postcategory_id to the relevent name, how can i add hyphens to the name. lets say:

/post/tips-for-today/some uuid

i want it to be like this. but it comes like this

/post/tips%20for%20today/some uuid

pickab00 started a new conversation Trying To Get Property Of Non-object • 6 days ago

I have a route setup like so:

/posts/{category}/{id}

so it comes something like this:

/posts/2/this id is a uuid

When i change the category id to something else, it gives me "Trying to get property of non-object" error. Its because the id with that category id does not exist?

Here is my controller:

public function post_single_page($postcategory_id, $id){
    
        $show_post = Post::where('postcategory_id', $postcategory_id)->where('id', $id)->first();

        return view('/front-end/show_post_single', compact('show_post'));

    }

how can i prevent this from happening? to at least give me a 404. what is the right method to achieve this.

Thanks

10th January, 2018

pickab00 started a new conversation Jquery FadeIn() Not Working • 1 week ago

I have my code as follows.

Here is my jquery:

$(function () {
        $(".cat-box").slice(0, 6).show();
        $("#loadMore").on('click', function (e) {
            e.preventDefault();
            $(".cat-box:hidden").slice(0, 6).fadeIn();
            if ($(".cat-box:hidden").length == 0) {
                $("#load").fadeOut('slow');
            }
        });

    });

Here is my CSS:

.cat-box {
    display:none;
    padding: 10px;
    border-width: 0 1px 1px 0;
    border-style: solid;
    border-color: #fff;
    box-shadow: 0 1px 1px #ccc;
    margin-bottom: 5px;
    background-color: #f1f1f1;
}

Finally html:

<div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="categories-boxes-container margin-top-5 margin-bottom-30">

                    <!-- Box -->
                    <a href="listings-list-with-sidebar.html" class="category-small-box cat-box">
                        <i class="im im-icon-Hamburger"></i>
                        <h4>Eat & Drink</h4>
                    </a>

                </div>
            </div>
        </div>
    </div>

I kept only one in the above code. But basically there are about 20 same code copy pasted for testing. fadeIn() will not work.

Thanks

7th January, 2018

pickab00 left a reply on "SQLSTATE[HY000]: General Error: 1364 Field 'name' Doesn't Have A Default Value • 1 week ago

It means your User's "name" field is null. A null is being passed and the user tables "name" field can not be null.

why are you updating users information using PatientControlller?

Do you want your logged in users id to go to patient tables user_id field?

pickab00 started a new conversation Google Maps API Error • 1 week ago

I have a laravel application which uses google maps API. What it basically does is, save a location when the user clicks on any area of the map.

The problem is that i am getting this error:

places_impl.js:9 Uncaught TypeError: Cannot read property 'value' of null

I have copied the code from this post: http://www.piedcode.com/tutorial-creating-a-webapp-with-google-maps-and-laravel/

Sometimes it causes the map to not load. The map will just stay still and it is not interactable. And then there are times where the map div will display nothing at all and complete white.

Why is this error being caused? It says can not read property 'value' of null. Which should mean that the element is missing right?

Also here is the exact line from the file which causes the issue. hope this helps:

C=a.value;this.Mc(this.C);this.m=b||"";this.F=!1;this.B=!("placeholder"in _.Y("input"));b=a.getAttribute("placeholder");null==b?this.B||a.setAttribute("placeholder",this.m):this.m=b;v9(this);b=_.nm(a);var c=b.createElement("div");

Many Thanks

6th January, 2018

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

Thanks this is exactly what i needed

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

Will this prevent from updating using the inspect element action? I mean if someone goes to inspect element and change the /{uuid} to some other posts uuid which does not belong to that user?

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

How to achieve this? Could you link me to the right direction

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

I want to show the post using post_id because if i show the post using uuid, a user might copy the uuid and go to inspect element and paste it on the form action and update some other post. If this is not the right way to achieve this, could you please suggest the right method.

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

They both are uuid

I want the id to be able to update post and post_id to show a post

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

I just want to know why its displaying when i give the id on the url. but it does not work when i give post_id on url. why is that

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

Sorry but is it suppose to be like this?

route(route('post.show', ['id' => $post->post_id])

['id' -> $post->post_id] to ['id' => $post->post_id]

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

This is the show method:

public function show($id)
    {
        return view('/user-dashboard/post/show');
    }

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

Here is my controller:

public function displayAll(){

        $posts = Post::all()->where('user_id', '=', Auth::user()->id);

        return view('/user-dashboard/post/all-post', compact('posts'));


    }

Here is the route:

Route::get('/dashboard/posts/show/{post_id}', '[email protected]')->name('post.show');

and the above question is blade.

pickab00 left a reply on How To Show Post Using Another Column Than ID • 1 week ago

@topvillas Sorry i updated my question. Anchor was not showing before. I removed "" from href. Theres the original question now.

pickab00 started a new conversation How To Show Post Using Another Column Than ID • 1 week ago

I have a table called Post and i want to show the different single posts using the show method. But i want to use my post_id instead of id.

The thing is i am using id for updating my posts. but i want to use post_id to show the posts. when i try {{$post->name}} it gives me 404. Because the id was not found. Does it has to do with id being the primary key? how can i achieve this?i want to update the posts using id but show the posts using post_id column.

thanks

5th January, 2018

pickab00 left a reply on Undefined Variable: Errors • 1 week ago

This solved it

Thanks

pickab00 left a reply on How To Make A Drop Down Menu Which Will Change The Table Content Depending On The Selected Value • 1 week ago

Nice :D

So i could use jquery's change to achieve this. In basic it will be calling to ajex. So make it a GET method and get the data to the table when the value on the changes.

That did make sense right? :)

Thanks for the help. This is what i needed. I'll reply to this post if I get stuck

pickab00 started a new conversation Undefined Variable: Errors • 1 week ago

I have created a errors/404.blade.php to create a custom 404 page. and i have @extends('layouts.app') on my 404.blade.php

The thing is, my app.blade.php has this line of code:

@if ($errors->any())
                                    <div class="alert alert-warning">
                                    <ul>
                                            @foreach ($errors->all() as $error)
                                                <li class="warning"><i class="sl sl-icon-info"></i>{{ $error }}</li>
                                            @endforeach
                                        </ul>
                                    </div>
                                @endif

And so it gives me the undefined variable error. This is a bit strange and i do not understand why it should give the error. Could someone please explain why this is happening? Thanks

4th January, 2018

pickab00 left a reply on Laravel MethodNotAllowedHttpException • 2 weeks ago

well i do have CRUD with the right requests. But laravel does not give me the 404 when i enter a non existing route. The controllers being used are using auth middleware. so /dashboard/post/anythingelse gives me error instead of 404

i did double check yesterday because i had a slight idea that i might have had mistakenly written get on a post. But it seems to be right

pickab00 left a reply on Laravel MethodNotAllowedHttpException • 2 weeks ago

@bobbybouwmann No i do not have a route catcher. Could you explain a bit. So i should put this in a group with auth middleware and use try catch to see if a route exists? and if not, then return a 404 right? Is this the way to achieve this?

I am currently not on my computer but thats basically all the routes i have. the rest are just /create, /{id}/edit etc... They all have their right actions. post, get, delete, patch

pickab00 started a new conversation How To Make A Drop Down Menu Which Will Change The Table Content Depending On The Selected Value • 2 weeks ago

I have a drop down with the values which are being taken from a table. I have a post table and a post_category table. the post_category tables id is the foreign key to post table as post_category_id.

I want the pages table to change its content when i choose an option from the drop down.

I am new to this bit.

Thanks

pickab00 left a reply on Laravel MethodNotAllowedHttpException • 2 weeks ago

@bobbybouwmann There is no route named /dashboard/post/somethingelse. I should have updated my question sorry. It should give me a 404. Because that route does not exist. My question is, why is it giving me the error instead of 404?

3rd January, 2018

pickab00 started a new conversation Laravel MethodNotAllowedHttpException • 2 weeks ago

I have some routes which looks like this:

Route::get('/dashboard/post/all', '[email protected]')->name('listing.all');
Route::get('/dashboard/post/verified', '[email protected]')->name('listing.verified');
Route::get('/dashboard/post/pending', '[email protected]')->name('listing.pending');
Route::get('/dashboard/post/active', '[email protected]')->name('listing.active');
Route::get('/dashboard/post/inactive', '[email protected]')->name('listing.inactive');

The issue is when i type (e.g. /dashboard/post/somethingelse) i get Method Not Allowed Http Exception and it is blank.

My Controller looks like this:

public function displayAll(){

        $listings = Listing::all()->where('user_id', '=', Auth::user()->id);

        return view('/user-dashboard/listing/all-listing', compact('listings'));
    }

It looks almost same for every other route only the where changes.

Can you please explain in depth of whats going on?

Thanks

31st December, 2017

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

@Snapey I am using uuid to edit the user account detail but i also have an id on users table which will be referencing to other tables user_id. So no issues there.

Thanks a bunch for clearing everything out

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

@Snapey i have one last question. I have about 3 other tables which i am using the id as uuid. so there is no separate column called uuid but the id will changed.

my id column is:

$table->uuid('id'); $table->primary('id'); (following the documentation).

Is this safe? Is this how it should be done?

I now have "http://something.com/admin/blog/{{the id which is a uuid of the post}}/edit".

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

@Snapey Ok got it working. Thank you for the suggestion. I completely forgot about the increment.

If i use the id as the primary key then it is not updating. Because the uri is expecting id and i am giving the uuid.

Also i am using id on other tables to reference user_id. so it will be user_id = 1. and not the uuid. i am using the uuid just to mask the form action so someone wont be able to inspect element and read my user id's. I am already using the webpatser/laravel-uuid so i needed help with this.

Anyways. Thanks

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

Here is the User model:

protected $fillable = [ 'uuid', 'name', 'email', 'mobile', 'address', 'profilepicture', 'password', ];

protected $primaryKey = 'uuid';

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

public static function boot()
{
    parent::boot();
    self::creating(function ($model) {
        $model->uuid = (string) Uuid::generate(4);
    });
}

public function getRouteKeyName()
{
    return 'uuid';
}

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

@Snapey i used:

public function edit()
{
    return request()->user()->uuid;
}

And it displays 339. I checked the uuid on my db and it goes something like 339hdjja-47dhskd... And so on.

Why is it being trimmed?

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

@Snapey I am using $user variable to call it from my html collective form as mentioned above.

I have used model to bind with the form and when ever i use $user->uuid instead of $user->id, i get the form action something like this: action = "http://something.com/dashboard/account/3300". It does not give me the original UUID from the db column uuid when i check inspect element.

I have also changed my primary key from id to uuid in my User model.

Could you please explain why the {uuid} is coming as a number and not the actual uuid?

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

@Snapey I've already added that to the model. Does not seem to work

30th December, 2017

pickab00 left a reply on Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

@Snapey With this current setup, it gives me page not found. It is because the URI expects the primary key which is the id. But i want to use uuid instead of id. I want this just to update user account detail.

pickab00 started a new conversation Use UUID Field Instead Of ID Field To Update User Profile • 2 weeks ago

My User ID is unique and many tables are using the user_id. I don't want to change the ID to a UUID. I am using webpatser/laravel-uuid Package.

Here is my controller:

public function edit()
    {
        $authUser = Auth::user()->id;

        $user = User::findOrFail($authUser);

        return view('/user-dashboard/account/edit-account', compact('user'));
    }

I am currently getting the id of the authenticated user and using that in my view.

Here is my view form:

{!! Form::model($user, ['method'=>'PATCH', 'files'=>true , 'action'=>
['[email protected]', $user->uuid]]) !!}

I am using HTML Collective. $user->uuid but it does not work. I did set the primary ket to uuid but changing that causes to not login.

Here is my route:

//User Account Routes
Route::get('/dashboard/account/', '[email protected]')-            >name('useraccount.edit');
Route::patch('/dashboard/account/{uuid}', '[email protected]');
//End User Account Routes

Hope this info helps. Thanks

pickab00 left a reply on Help With Laravel Update Method • 2 weeks ago

@Snapey one more question. Can i store a random number (about 6 digits) to db and use that instead of using the ID? I guess it will be a bit secure as it will be randomly generated right?

pickab00 left a reply on Help With Laravel Update Method • 2 weeks ago

@Snapey Thanks a bunch. That solves one issue. This works for now :)

pickab00 started a new conversation Help With Laravel Update Method • 2 weeks ago

This is weird and i don't know how to get pass this.

The problem is that i have a form with action="http://something.com/admin/post/2". This is what happens in my update method. The route is set to "Route::patch('/post/{id}', 'AdminBackend\[email protected]');"

If i go to inspect element on firefox and change the actions {id} from 2 to 1 and press the update button, it updates the ID number 1 information. I mean obviously that basically what the form is asking to do.

My question is, how can i prevent this from happening?

Thanks

pickab00 left a reply on How To Not Allow Access To Other Users Data • 2 weeks ago

Ok so for anyone with the same doubt, if you are using --resource on the controller for the posts, here is my edit method:

public function edit($id) {

    $user = Auth::user()->id;

    $postEdit = Post::where('user_id', '=' , $user)->findOrFail($id);

    return view('/user-dashboard/posts/edit', compact('postEdit '));

}

Now if you change the ID from the URL to something which does not belong to the current logged in user id, it will say page not found.

Hope this helps :)

pickab00 started a new conversation How To Not Allow Access To Other Users Data • 2 weeks ago

Hi

In my website, i don't want to allow the authenticated user to access others data by typing the ID of the post on URL and be able to edit them or see them.

I have a dashboard which each user can access and add/edit a post. But the URL something like this:

something.com/dashboard/posts/2/edit (This is the edit)

something.com/dashboard/blogposts/2/edit (This is the edit)

something.com/dashboard/posts/all (Select and show list where user_id = authenticated user)

I actually have a Posts and Blogposts.

The thing is, the user can access others data by changing the ID in the URL. although the authenticated users post ID is 1 and 2, he is able to edit 3 and 4 as well. How can i make it so it redirects the user back to "something.com/dashboard/posts/all".

Thanks

23rd December, 2017

pickab00 left a reply on How To Add Class="active" To The Current Selected Menu Item • 3 weeks ago

@kfirba nice work. This package seems to be the best fit for now. It's easy and lightweight and doesn't cause any confusion. I may refer to your method on a later project but this one contains too many links and thr package lets me not refer to my documentation if i wanted to fix something later on.

Thanks anyways :)

pickab00 left a reply on How To Add Class="active" To The Current Selected Menu Item • 3 weeks ago

Thanks. Both solutions works like a charm but i'd prefer using the package as its a lot more easier using named routes and saves some lines and time. I have a lot of routes (more than what was posted) which needs active class.

@Yama Thanks :)

pickab00 started a new conversation How To Add Class="active" To The Current Selected Menu Item • 3 weeks ago

I have a dashboard which i downloaded. But it does not add active class to the current selected menu item. How to achieve this?

Here is my html:

            <ul data-submenu-title="Main">
                <li class="active"><a href="#"><i class="sl sl-icon-settings"></i> 
Dashboard</a></li>
            </ul>

            <ul data-submenu-title="Listings">
                <li><a><i class="sl sl-icon-home"></i> My Listings</a>
                    <ul>
                        <li><a href="#">All <span class="nav-tag white"></span></a></li>
                        <li><a href="#">Pending <span class="nav-tag yellow"></span></a></li>
                    </ul>
                </li>

                <li><a><i class="sl sl-icon-layers"></i> My Rentals</a>
                    <ul>
                        <li><a href="#">All <span class="nav-tag white"></span></a></li>
                        <li><a href="#">Pending <span class="nav-tag yellow"></span></a></li>
                    </ul>
                </li>
                <li><a href="#"><i class="sl sl-icon-plus"></i> Add Listing</a></li>
                <li><a href="#"><i class="sl sl-icon-plus"></i> Add Rentals</a></li>
            </ul>

            <ul data-submenu-title="Account">
                <li><a href="#"><i class="sl sl-icon-user"></i> My Profile</a></li>
                <li><a href="#"><i class="sl sl-icon-logout"></i>Logout</a></li>
            </ul>

        </div>
    </div>

22nd December, 2017

pickab00 left a reply on Add Multiple Images To Database • 3 weeks ago

@Snapey in that case its better to generate a random name for the filename. That way, there would be no replicates of filename right? And by random name i mean a random number as the filename and input that to the db. I have used this method before when i was using slim application framework and i didnt have any issue. I guess that would be the best practice. Wouldn't it?

pickab00 left a reply on Add Multiple Images To Database • 3 weeks ago

@Snapey many thanks. This looks fine but i figured why it was passing one value.

The above code (original post) had $input, $input1 and $input2. Which should have been just $input as my variable is $input to save all the data to DB.

I have now put it in a loop and it works fine. Thanks for the help :)

21st December, 2017

pickab00 left a reply on Add Multiple Images To Database • 3 weeks ago

@Yama I'm getting 'illegal offset type in isset or empty' error. Also $file should be $image

pickab00 left a reply on Add Multiple Images To Database • 3 weeks ago

@wing5wong I used the if statement first and for some reason it passes just the first value.

@Snapey I have 3 columns in my listings table. 'image', 'image1', 'image2'. I want three images name to be saved to three columns.

pickab00 started a new conversation Add Multiple Images To Database • 4 weeks ago

Ok first off, i am very new to understanding this concept so please bare with me.

I have a code which inserts the file name to DB. Then i went on and replicated the code thrice and still one value is being passed to DB. Just the firs image. The second and third wont work. I wanted to know where i am heading and if anyone could help.

Here is my create.blade.php:

                <input type="file" name="image">
                <input type="file" name="image1">
                <input type="file" name="image2">

Here is my Controller:

$user_id = Auth::user()->id;

        $input = new Listing;

        $input->user_id = $user_id;
        $input->name = Input::get('name');
        $input->category = Input::get('category');
        $input->keyword = Input::get('keyword');
        $input->location = Input::get('location');
        $input->address = Input::get('address');
        $input->zipcode = Input::get('zipcode');
        $input->image = Input::get('image');
        $input->detail = Input::get('detail');
        $input->price = Input::get('price');
        $input->phone = Input::get('phone');
        $input->mobile = Input::get('mobile');


        if ($file = $request->file('image')){

            $name = $file->getClientOriginalName();

            $file->move('images/listings', $name);

            $input['image'] = $name;

        }

        elseif ($file1 = $request->file('image1')){

            $name1 = $file1->getClientOriginalName();

            $file1->move('images/listings', $name1);

            $input1['image1'] = $name1;

        }

        elseif ($file2 = $request->file('image2')){

            $name2 = $file2->getClientOriginalName();

            $file2->move('images/listings', $name2);

            $input2['image2'] = $name2;

        }


        $input->save();

        return redirect()->back();

Thanks in advance

Edit Your Profile
Update

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