lundi 29 octobre 2018

public/index.php to remove / redirect to domain in laravel

I have developed one laravel application. Initially we have executing http://127.0.0.1/laravel_app/public this url structure.

Ater completing application i have moved to server with domain.

Example: http://www.example.com it working fine. I have integrated .htaccess to remove public. its working fine.

But i have try to http://www.example.com/public/index.php above url manually typed site will display.

How can remove if users enter manually enter this type of URL http://www.example.com/public/index.php

Kindly guide me.

Thank you.



via Chebli Mohamed

Update pivot table to create dynamic menu(menu and sub items) - Laravel

The case is : I want to make a dynamic sidebar when the user choose a book from the list -I used checkboxes -it should be saved in a pivot table with the category id so this will let me to to generate a dynamic sidebar for each user for example:

user 1 sidebar

- category 1

book 1 book 2

- category 2

book1 book2

My tables :

 user_book
-----------------------------------------
 user_id| book_id|category _id
-----------------------------------------


user_categories
-----------------------------------------
 user_id| book_id|category _id
-----------------------------------------


 books
-----------------------------------------
id| book_name|category_id|
-----------------------------------------

categories
-----------------------------------------
id| category|
-----------------------------------------

my code:

$user->books()->sync($request->input('books_ids'));// to save books ids -array of ids- but don't know how to insert the related category for each book in the pivot table.

and to generate my sidebar:

 $user->categories()->with('books')->get();

so my questions are : 1. is this the right way to make a dynamic sidebar and what is the best way? 2. how can I insert the related category in the pivot table ?



via Chebli Mohamed

Laravel, Vuejs redirect with params

I have an option to search for users, what i would like to achieve is for the search to return an array with users to a new page. I made this work with window.location after my request but that crashes when there is to many users and not a way i would like to achieve this.

If you know any other way to tackle this please let me know.

Here is what i am currently doing:

Search.vue:

<template>
 <input type="text" v-model="query" @keyup.enter="search()"/>
 <button @click="search()"  type="button">
</template>


<script>
export default {
    data() {
        return {
            users: [],
            query: ''
        }
    },
    methods: {
        search: function() {
            this.users = [];
            this.loading = true;
            axios.get('/api/search?q=' + this.query).then((response) => {
             this.users = response.data;
               this.loading = false;
               this.query = '';
               window.location = '/search/?users=' + JSON.stringify(this.users);
            });
        }
    }
};
</script>

SearchController.php:

class SearchController extends Controller
{
    public function search(Request $request)
    {
        $error = ['error' => 'No results found, please try with different keywords.'];

        if ($request->has('q')) {
            $users = User::search($request->get('q'))->get()->load('stats');
            return $users->count() ? $users : $error;
        }
        return $error;
    }
}



via Chebli Mohamed

mapWithKeys in laravel ,i dont understand how do it work?

I saw the example of laravel, but i dont understand how do it work.

for this example:

$collection = collect([
    [
        'name' => 'John',
        'department' => 'Sales',
        'email' => 'john@example.com'
    ],
    [
        'name' => 'Jane',
        'department' => 'Marketing',
        'email' => 'jane@example.com'
    ]
]);

$keyed = $collection->mapWithKeys(function ($item) {
    return [$item['email'] => $item['name']];
});

$keyed->all();

someone can explain detail of it?



via Chebli Mohamed

Creating a Google Map in Laravel,

I try to display Google Map which is display an address from database(I have address column in DB table). For this I made a blade, and bind to route and path it with controller. I am having display issue.

My step is right below. I used this google API.

https://github.com/farhanwazir/laravelgooglemaps

And set the route:

Route::get('/show', 'PagesController@map');

Set the controller:

public function map(){

    $config['center'] = allestates::where('address')->get();
    $config['zoom'] = '10';
    $config['map_width'] = '300px';
    $config['scrollwheel'] = false;

    GMaps::initialize($config);

    $map = GMaps::create_map();

    return view(pages.show)->with('map', $map);
}

And in my blade. This is how I am calling it in body tag.



But getting this error.

Undefined variable: map (View: /var/www/html/laravel/resources/views/pages/show.blade.php)

Any idea what the problem is?



via Chebli Mohamed

'sudo service apache2 start' doesn't work on ubuntu18.04

I've installed laravel on my ubuntu18.04. And I made /etc/apache2/sites-available/laravel.conf file.

<VirtualHost *:80>
    ServerName yourdomain.tld

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/your-project/public

    <Directory /var/www/html/your-project>
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Then run these code on terminal:

sudo a2dissite 000-default.conf
sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo service apache2 restart
But when I run "sudo service apache2 restart", An error code occurs.
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

And I ran both of "systemctl status apache2.service" and "journalctl -xe" but there were also error codes:

apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Mon 2018-10-29 01:48:17 PDT; 5min ago
  Process: 40882 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

Oct 29 01:48:17 ubuntu apachectl[40882]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress thi
Oct 29 01:48:17 ubuntu apachectl[40882]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Oct 29 01:48:17 ubuntu apachectl[40882]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Oct 29 01:48:17 ubuntu apachectl[40882]: no listening sockets available, shutting down
Oct 29 01:48:17 ubuntu apachectl[40882]: AH00015: Unable to open logs
Oct 29 01:48:17 ubuntu apachectl[40882]: Action 'start' failed.
Oct 29 01:48:17 ubuntu apachectl[40882]: The Apache error log may have more information.
Oct 29 01:48:17 ubuntu systemd[1]: apache2.service: Control process exited, code=exited status=1
Oct 29 01:48:17 ubuntu systemd[1]: apache2.service: Failed with result 'exit-code'.
Oct 29 01:48:17 ubuntu systemd[1]: Failed to start The Apache HTTP Server.

How can I start Apache Http server. Somebody help me!



via Chebli Mohamed

Vuetify v-select in Laravel Views

I want to use Vuetify in Laravel's Blade Template. Unfortunately v-select does not seem to return any value. Maybe you can help me with that. Everything else works just fine except that.

Blade Template

Passed items

Result

(newbie in stackoverflow)



via Chebli Mohamed