lundi 27 novembre 2017

how to retrieve data from db for registation on laravel?

how to retrieve data from db for registation on laravel? I have two tables database, users and kode_instansi, I want to continue at the time of registration there is a form select that displays all data from the table kode_instansi. help master

controller

view



via Chebli Mohamed

laravel 5.5 - inject more data into paginate collections

I have 2 tables:

profiles - for user profiles. posts - for user posts.

posts only has a user_id from profiles, to keep the table clean.

my HomeController have a function that get all published posts:

public function index()
    {
        $posts = Post::where('publish','=',1)->orderBy('created_at', 'DSC')->paginate(5);
        return view('home',['posts'=>$posts]);
    }

which post only contains user_id to link it back to its owner. How can I use the user_id from $posts to retrieve user data (user_name, user_image) and append it to its specific post?

I tried:

foreach ($posts->items() as $p) {
 $profile = Profile::where('user_id','=',$p->user_id)->first();
 $p->put('profile',$profile);
}

and I get an error:

Call to undefined method Illuminate\Database\Query\Builder::put()

How can I resolve this?



via Chebli Mohamed

Getting a slug to save in vue

I'm using both vue and laravel and I'm trying to create a product form that creates a slug as you type. I've managed to get the slug to show up as you type but I'm not sure as to how I should save it to my database.

My vue

<template>
    <div class="product-form">
        <form v-on:submit="onSubmit(model)">
            <div class="form-group">
                <label for="title">Title</label>
                <input type="text" id="title" class="form-control" name="title" v-model="model.title">
                <input type="hidden" name="slug" title="slug" :value="slug(model.title)">
                <p></p>
            </div>

            <input type="submit" class="btn btn-default" value="Save"></input>
        </form>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                model: {
                    title: '',
                    slug: '',
                },

            };
        },

        methods: {
             slug() {
                var title = this.model.title;

                var slug_test = title.replace(/\s+/g, '-');
                return slug_test;
            },

            onSubmit: function(model){

                event.preventDefault();

                this.$http.post('/database/articles', model)
            }
        },
    }
</script>



via Chebli Mohamed

@foreach in @foreach have double data laravel

I have two array $softwarelist and $virt_software_select when i use @foreach in blade template like below code i got checked but $softwarelist is double in label.

$softwarelist =["Adobe Photoshop","Corel Draw","My SQL","Oracle"];
$virt_software_select=["Adobe Photoshop","Oracle"];

@foreach($softwarelist as $slst)
    @foreach($virt_software_select as $sw_usr)
        @if($slst->software==$sw_usr->virtualize_software)
            <label>
                <input type="checkbox" checked name="virt_software[]" value=""/> 
                  
            </label>
        @else
            <label>
                <input type="checkbox" name="virt_software[]" value=""/> 
                  
            </label> 
        @endif
    @endforeach
@endforeach

How can i get checked the same data in two array but not double data with $softwarelist in laravel?



via Chebli Mohamed

rename redis namespace pattern on laravel?

It's possible to rename redis namespace pattern on laravel session storage?

Laravel Redis Namespace

Thank in advance



via Chebli Mohamed

Laravel 5 How to populate same view multiple times with different data and cycle between pages

I am quite new to Laravel and I'm trying to build a small application that uses nested views (something like shown below)

enter image description here

To explain, I have an array of $categories which can vary in quantity. Each $category contains a different number of $questions. I want to create a page of $questions for each $category using the same view (so each $category on a new page).

I want to start with a summary page and be able to cycle Next and Back from each page (except for the first and last pages).

I have created my controller that currently returns me $categories and $questions and I have fed them into a view. I just don't know how to split them up by $category and cycle through the same view.



via Chebli Mohamed

Redirect to non-www gives 404

I have DNS @ and www A-records pointing to my server IP. In .htaccess I have:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301]


    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

But when I visit www.site.com, I get site.com/app.php and "Sorry, the page you are looking for could not be found."

What can be the problem?



via Chebli Mohamed