hemal

hemal

Member Since 1 Year Ago

Experience Points 1,280
Experience Level 1

3,720 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 0
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.

20 Feb
1 year ago

hemal started a new conversation React Component Not Show In Laravel

my component like below

import React, { Component } from 'react';
import ReactDOM from 'react-dom';

export default class User extends Component {
    render() {
        return(
            <div className="container">
                <h2>
                    User Listing
                </h2>
                <table className="table table-bordered">
                    <tead>
                        <tr>
                            <th>Id</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Action</th>
                        </tr>
                    </tead>
                    <tbody>
                        <tr>
                            <td>1</td>
                            <td>adam</td>
                            <td>[email protected]</td>
                            <td>
                                <a href="" className="btn btn-primary">
                                    Edit
                                </a>
                                <a href="" className="btn btn-danger">
                                    Delete
                                </a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        );
    }
}
if (document.getElementById('user')) {
    ReactDOM.render(<User />, document.getElementById('user'));
}

and I have include that in blade file like below

<div id="user"></div>

but nothing show i have include component in app.js file what did I do wrong there is an error like below in console

Uncaught TypeError: Cannot read property 'Component' of undefined
    at Object.<anonymous> (app.js:53799)
    at __webpack_require__ (app.js:20)
    at Object.<anonymous> (app.js:10273)
    at __webpack_require__ (app.js:20)
    at Object.<anonymous> (app.js:10249)
    at __webpack_require__ (app.js:20)
    at validateFormat (app.js:63)
    at app.js:66
01 Nov
1 year ago

hemal started a new conversation Why User Not Redirecting In Vue

my main.js file like below

Router.beforeEach(
    (to, from , next) => {
        if(to.matched.some(record => record.meta.forVistors)) {
            if(Vue.auth.isAuthenticated()) {
                next ({
                    path: '/feed'
                })
            } else next()
        } else next()
    }
)

in my routes.js file like below

const router = new VueRouter({
    routes: [
        {
            path: "/login",
            component: Login,
            meta: {
                forVisitors: true
            }
        },

        {
            path: "/register",
            component: Register,
            meta: {
                forVisitors: true
            }
        },

        {
            path: "/feed",
            component: Feed,
        }
    ]
})

why its not redirecting after login, what did I do wrong please help me

hemal started a new conversation Origin Http://localhost:8080 Not Found In Access-Control-Allow-Origin Header.?

I have use cors middleware to get rid of that but its still give the error I have install cors throw composer and add the provider and change my RouteServiceProvider.php like below

protected function mapApiRoutes() {
        Route::prefix('api')
            ->middleware('api', 'cors')
            ->namespace($this->namespace)
            ->group(base_path('routes/api.php'));
    }

add the cors middleware and I have publish this but still getting the error

my console like below

Failed to load http://localhost:8000/api/test: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
Uncaught (in promise) Response {url: "http://localhost:8000/api/test", ok: false, status: 0, statusText: "", headers: Headers, …}

my api.php class like below

Route::get('/test', function () {
    return response()->json([
        'user' => [
            'first_name' => 'Hemal',
            'last_name' => 'Herath',
        ],
    ]);
});

in my vue class i have create a method like below

methods: {
            test() {
                this.$http.get('http://localhost:8000/api/test')
                    .then(function(response) {
                        console.log(response)
                    })
            }
        }

what did I do wrong please tell me im new to this stuff

27 Oct
1 year ago

hemal left a reply on How To Retrieve Data In Array Object?

@kfirba there is no such column in posts table its in user table im getting those data because im using $with, users is an object

hemal started a new conversation How To Retrieve Data In Array Object?

if i return this query $posts = Post::all(); reult will be like below

Array[102]
0:Object
id:1
user_id:12
content:"Ea aliquam aut ea. Soluta impedit pariatur cupiditate fugiat. Qui temporibus commodi quibusdam ratione. Doloribus hic qui totam. Voluptatibus voluptatum ex porro sit eius. Aut impedit suscipit quae optio nobis. Amet aliquam qui et dolorem omnis."
created_at:"2017-10-27 06:57:17"
updated_at:"2017-10-27 06:57:17"
user:Object
id:12
name:"Abel Altenwerth"
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"abel-altenwerth"
gender:0
created_at:"2017-10-27 06:57:05"
updated_at:"2017-10-27 06:57:05"
likes:Array[0]

I want to get posts that have the user object slug equivalent to what im getting throw parameters, How can I do that below code is my controller

    public function index($slug) {


        $posts = Post::all();

        return $posts;

    }

How can I retrieve posts that have slug that im getting throw parameters

hemal left a reply on Why When I Retrieve Image Its Not Getting The Storage Data?

I have save all the users avatar like this defaults/avatars/female.png now its work

hemal left a reply on Why When I Retrieve Image Its Not Getting The Storage Data?

@mushood I have edited my question as u asked

hemal left a reply on Why When I Retrieve Image Its Not Getting The Storage Data?

I have edited the question, now I dont know how the others getting retrieving because theres nothing call avatars in public folder

anyway if i use like src="<?php echo asset("storage/$user->avatar") ?>"

its getting public so it want worki either

hemal started a new conversation Why When I Retrieve Image Its Not Getting The Storage Data?

Im try to retrieve all users data when im retrieving the avatar its not getting, blade file like below

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel-body">
                    @foreach($users as $user)
                        <li class="list-group-item">
                            <img src="{{ $user->avatar }}" width="40px" height="40px">
                            <a href="/profile/{{ $user->slug }}"><label>{{ $user->name }}</label></a> &nbsp; {{ $user->location }}
                            <br>
                        </li>
                    @endforeach
                </ul>
            </div>
        </div>
    </div>
</div>
@endsection

controller for above view like below

public function findfriends() {

        $users = Profile::leftJoin('users', 'users.id', 'profiles.user_id')->where('user_id', '!=', Auth::user()->id)->get();

        return view('findfriends', compact('users'));

    }

console says GET http://localhost:8000/public/defaults/avatars/female.png 404 (Not Found)

thats true nothings there

but when im retrieving profile data according to user it will retrieveing the data it will show the avatar path say like http://localhost:8000/storage/defaults/avatars/female.png

controller for single profile like below

    public function index($slug) {
        $user = User::where('slug', $slug)->first();
        return view('profiles.profile', compact('user'));
    }

view for above controller

<div class="panel-body">
                    <center>
                        <img src="{{ $user->avatar }}" width="140px" height="140px" style="border-radius: 50%">
                    </center>
                    <br>
                    <p class="text-center">
                        {{ $user->profile->location }}
                    </p>
                    <br>
                    <p class="text-center">
                        @if(Auth::id() == $user->id)
                            <a href="{{ route('profile.edit') }}" class="btn btn-info">Edit your profile</a>
                        @endif
                    </p>
                </div>

its saving in database like below

public/defaults/avatars/female.png

why its not getting like same when im try to get all users?? please help me

26 Oct
1 year ago

hemal started a new conversation How To Get Data Inside A Class Tag?

I have a span like below

<span class="'label label-' + chats.color[index]">{{ chats.user[index] }}</span>

I need to change the label color according to data in array

data() {
            return {
                message: '',
                chats: { 
                    message: [],
                    user: [],
                    color: []
                }
            }
        },
<ul class="list-group">
            <div class="pre-scrollable" v-chat-scroll>
                <li v-for="message,index in chats.message" class="list-group-item">
                    <p class="pull-right">{{ message }}</p>
                    <span class="'label label-' + chats.color[index]">{{ chats.user[index] }}</span>
                </li>
            </div>
        </ul>

How can I get data in array to style class

hemal started a new conversation Why Pusher Not Getting Send Data?

I have created a event and listener my event like below

<?php

namespace App\Events;

use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ChatEvent implements ShouldBroadcast {
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;
    public $user;

    public function __construct($message, User $user) {

        return $this->message = $message;
        return $this->user = $user;
    }

    public function broadcastOn() {
        return new PrivateChannel('chat');
    }
}

and I have give my keys correctly

my controller method like below

public function send() {

        $user = User::find(Auth::id());

        $message = 'Hello';

        event(new ChatEvent($message, $user));
    }

route like below

Route::get('/send', '[email protected]');

why its not giving data in pusher please help me

25 Oct
1 year ago

hemal left a reply on How Can I Get Data Inside An Array

Thank you @tykus, Can u tell me how can I retrieve it after I add the post It should display below, its adding after Irefresh the page

hemal started a new conversation How Can I Get Data Inside An Array

Im using a .vue class like below

<script>
    export default {
        mounted() {

        },
        data() {
            return {
                content: '',
                not_working: true,
                posts: []
            }
        },
        get_post() {
            this.$http.get('/get/post')
                .then((reponse) => {
                    this.posts = reponse.data
                })
        },
        methods: {
            create_post() {
                this.$http.post('/create/post', { content: this.content })
                    .then((reponse) => {
                        this.content = ''
                        new Noty({
                                type: 'success',
                                layout: 'topRight',
                                text: 'Your post has been published !'
                            }).show();
                        console.log(reponse)
                    })
            }
        },
        watch: {
            content() {
                if(this.content.length > 0)
                    this.not_working = false
                else
                    this.not_working = true
            }
        },
        http: {
            headers: {
                'X-CSRF-Token': $('meta[name=csrf-token]').attr('content')
            }
        },  
    }
</script>

there is a post array and im try to put data inside that array using get_post method

if i go to the url im getting data there are data like below

Array[10]
0:Object
id:102
user_id:1
content:"dddd"
created_at:"2017-10-25 18:35:27"
updated_at:"2017-10-25 18:35:27"
user:Object
id:1
name:"Charity Pacocha"
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"charity-pacocha"
gender:0
created_at:"2017-10-25 08:40:48"
updated_at:"2017-10-25 08:40:48"
likes:Array[0]
1:Object
id:101
user_id:1
content:"Configuring Searchable Data By default, the entire toArray form of a given model will be persisted to its search index. If you would like to customize the data that is synchronized to the search index, you may override the toSearchableArray method on the model:"
created_at:"2017-10-25 08:43:00"
updated_at:"2017-10-25 08:43:00"
user:Object
id:1
name:"Charity Pacocha"
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"charity-pacocha"
gender:0
created_at:"2017-10-25 08:40:48"
updated_at:"2017-10-25 08:40:48"
likes:Array[2]
0:Object
id:10
user_id:3
post_id:101
created_at:"2017-10-25 17:59:14"
updated_at:"2017-10-25 17:59:14"
user:Object
id:3
name:"Bettye Nienow Jr."
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"bettye-nienow-jr"
gender:0
created_at:"2017-10-25 08:40:51"
updated_at:"2017-10-25 08:40:51"
1:Object
id:25
user_id:1
post_id:101
created_at:"2017-10-25 18:07:37"
updated_at:"2017-10-25 18:07:37"
user:Object
id:1
name:"Charity Pacocha"
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"charity-pacocha"
gender:0
created_at:"2017-10-25 08:40:48"
updated_at:"2017-10-25 08:40:48"
2:Object
id:98
user_id:9
content:"Aut ut doloremque at placeat repellat. Quisquam neque eaque nemo molestiae veritatis quia. Ratione dolorem omnis autem sequi quia aut dolore. Et eligendi sit molestias in sequi. Veritatis nisi vel laudantium. Molestiae et autem eos. Et quod minus nostrum aliquam atque natus. Quo fuga quia illum aut eveniet. Nihil labore tempora sint ut. Vel qui molestias excepturi optio optio atque. Asperiores quia et nisi voluptas."
created_at:"2017-10-25 08:41:10"
updated_at:"2017-10-25 08:41:10"
user:Object
id:9
name:"Rubye Shields"
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"rubye-shields"
gender:0
created_at:"2017-10-25 08:40:53"
updated_at:"2017-10-25 08:40:53"
likes:Array[1]
0:Object
id:19
user_id:1
post_id:98
created_at:"2017-10-25 18:04:33"
updated_at:"2017-10-25 18:04:33"
user:Object
id:1
name:"Charity Pacocha"
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"charity-pacocha"
gender:0
created_at:"2017-10-25 08:40:48"
updated_at:"2017-10-25 08:40:48"

how can I put those things inside posts array and use them

hemal started a new conversation How Can I Use A Link In Vue File

I have a like like below how can I use that <a href="/profile/{{ post.user.slug }}">{{ post.user.name }}</a>

below file is my .vue file

{{ post.user.name }} {{ post.created_at }}

                <div class="panel-body">
                    <p class="text-center">{{ post.content }}</p>
                    <like :id="post.id"></like>
                </div>
                
            </div>
        </div>
    </div>
</div>

import Like from './Like.vue'
export default {
    mounted() {
        this.get_feed()
    },
    components: {
        Like
    },
    methods: {
        get_feed() {
            this.$http.get('/feed')
                .then((response) => {
                    response.body.forEach((post) => {
                        this.$store.commit('add_post', post)
                    })
                })
        }
    },
    computed: {
        posts() {
            return this.$store.getters.all_posts
        }
    }
}   
.avatar-feed { border-radius: 50% }
24 Oct
1 year ago

hemal started a new conversation Call To Undefined Relationship

Im try to get user details according to post like below

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model {

    public $with = ['user'];

    protected $fillable = ['user_id', 'content'];

    public function user() {

        return $this->blongsTo('App\User');
    }
}

but it gives a error like below

Call to undefined relationship [User] on model [App\Post].

Im try to do this refering to this link https://www.youtube.com/watch?v=TzMysp74nyE&index=40&list=PLZAiN3wmUtzV1eI7mAxERQaE2LkyA5Nh6

hemal started a new conversation How Can I Use A Route In .vue File

in my .vue file there is a route like below

<template>
    <li>
        <a href="{{ route('notifications') }}">Unread notifications
            <span class="badge">{{ all_nots_count }}</span>
        </a>
    </li>
</template>

It going to correce route but it give a compile error in npm run watch like below

can someone tell me why

ERROR in ./node_modules/vue-loader/lib/template-compiler?{"id":"data-v-0f140850","hasScoped":false,"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0&bustCache!./resources/assets/js/components/UnreadNots.vue
(Emitted value instead of an instance of Error)
  Error compiling template:

  <li>
        <a href="{{ route('notifications') }}">Unread notifications
                <span class="badge">{{ all_nots_count }}</span>
        </a>
  </li>

  - href="{{ route('notifications') }}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.

 @ ./resources/assets/js/components/UnreadNots.vue 6:23-276
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss
23 Oct
1 year ago

hemal left a reply on Error In Broadcast Notification With Pusher And Laravel Echo Please Help Me?

its not going inside this method

listen() {
                Echo.private('App.User.' + this.id)
                    .notification((notification) => {
                          alert('new notification')
                    })
            }

hemal left a reply on Error In Broadcast Notification With Pusher And Laravel Echo Please Help Me?

Nothings change I dont know why its not getting subscribe

hemal left a reply on Error In Broadcast Notification With Pusher And Laravel Echo Please Help Me?

If I use that also Im getting the same error Im using laravel 5.5 so my BroadcastServiceProvider.php like

public function boot() {

        Broadcast::routes(['middleware' => 'auth']);

        require base_path('routes/channels.php');
    }

my channels.php route like below

<?php
Broadcast::channel('App.User.{user_Id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

hemal started a new conversation Error In Broadcast Notification With Pusher And Laravel Echo Please Help Me?

I want to broadcast my notification with pusher and laravel echo on a private channel

my bootstrap.js file like below

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '5c3621c15520b7e2fb02',
    cluster: 'ap2'
});

Pusher.log = function(message){

    window.console.log(message)
}

and my notification.vue file like below

<script>
    export default {
        mounted() {
            this.listen()
        },
        props: ['id'],
        methods: {
            listen() {
                Echo.private('App.User.' + this.id)
                    .notification( (notification) => {
                        alert('new notification')
                    })
              }
        }
    }
</script>

my BroadcastServiceProvider.php like below

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;

class BroadcastServiceProvider extends ServiceProvider {
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot() {

        Broadcast::routes();

        Broadcast::channel('App.User.*', function ($user, $userId) {
            return (int) $user->id === (int) $userId;
        });
    }
}

In the console it gives a error like below

Pusher : State changed : connecting -> connected with new socket ID 334.3086157
Pusher : No callbacks on private-App.User.1 for pusher:subscription_error

if I changed BROADCAST_DRIVER=driver

it gives a error like below

Pusher : State changed : connecting -> connected with new socket ID 
Pusher : No callbacks on private-App.User.1 for pusher:subscription_error

Internal server error says

"Missing argument 2 for App\Providers\BroadcastServiceProvider::App\Providers\{closure}(), called in C:\xampp\htdocs\l55-v2-social\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\Broadcaster.php on line 60 and defined"

How can I fix this Please help me

20 Oct
1 year ago

hemal started a new conversation What Have I Done Wrong Please Help Me Out ?

I have created a component call notification to use notification for notificaton using with pusher like below

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

<script>
    export default {
        mounted() {
            this.listen()
        },
        props: ['id'],
        methods: {
            listen() {
                Echo.private('App.User.' + this.id)
                    .notification( (notification) => {
                        alert('new notification')
                    })
              }
        }
    }
</script>

and I have use that inside my app.blade.php file like below

<notification :id="{{ Auth::id() }}"></notification>

my bootstrap.js file like below

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '5c3621c15520b7e2fb02',
    cluster: 'ap2'
});

Pusher.log = function(message){

    window.console.log(message)
}

but if i go to login in browser it not show anything it gives a error like below

[Vue warn]: Failed to generate render function:

SyntaxError: Unexpected token } in

with(this){return _c('div',{attrs:{"id":"app"}},[_m(0),_v(" "),_m(1),_v(" "),_c('notification',{attrs:{"id":}})],1)}


(found in <Root>)
Pusher : State changed : connecting -> connected with new socket ID 322.2621542

hemal started a new conversation After Refresh The Page Status Jump Back To 0 Again How Can I Fix That

Im try to create a simple social network

in my friend.vue file there is a ajax request like below

accept_friend() {
                this.loading = true
                this.$http.get('/accept_friend/' + this.profile_user_id)
                    .then( (response) =>{
                        //console.log(response)
                        if(response.body == 1){
                            this.status = 'friends'
                            this.loading = false
                        }
                    })
            }

route like below

Route::get('/accept_friend/{id}', '[email protected]_friend')->name('accept_friend');

and controller like below

public function accept_friend($id) {

        return Auth::user()->accept_friend($id);
    }

and there is trait


public function accept_friend($requester) {

        if ($this->has_pending_friend_request_from($requester) === 0) {

            return 0;
        }

        $friendship = Friendship::where('requester', $requester)
            ->where('user_requested', $this->id)->first();

        if ($friendship) {
            $friendship->update([
                'status' => 1,
            ]);

            return 1;
        }

        return 0;
    }

if i add a friend it says friends but if i refresh the page its changing the status to 0, how can i fix this

19 Oct
1 year ago

hemal started a new conversation How Can Use Noty Package With Laravel 5.5

I have use a session like below in my controller

Session::flash('success', 'Profile updataed');

and i have import below files

use Illuminate\Session\flash;
use Illuminate\Support\Facades\Session;

and I have run npm install noty command

in my assets folder bootstrap.js file i have include

require('noty');

and after that I have add below script code in my main layout file

<script>
        @if(Session::has('success'))
            noty([
                type: 'success',
                layout: 'top',
                text: '{{ Session::get('success') }}'
                ]);
        @endif
    </script>

but its not giving me a notification what did i do wrong

16 Oct
1 year ago

hemal started a new conversation Retrieve Image From Database?

I have added the path of image to database I have retrieve it using laravel by using

<img src="{{asset('img')}}/{{$user->img}}"/>

how can I do this in with vue in laravel I have retrieve normal data but I dont no how to display this

hemal started a new conversation How Can I Use CSRF Token With Axios Post Method?

Im new to vue in laravel. earlier when I want to save some data throw an action below form I can use {{ csrf_field() }}

How can I do that when using axios.post,

In my console it will give a error

CSRF token not found:

I know because I didnt defined that can someone tell me how to do that

my app.js file like below


require('./bootstrap');

window.Vue = require('vue');
var Vue = require('vue');
Vue.use(require('vue-resource'));

Vue.component('example', require('./components/Example.vue'));

const app = new Vue({
    el: '#new',

    data: {
        message: 'Update New Post:',
        content: '',
    },

    methods:{

        addPost(){
            axios.post('/addPost', {
              content: this.content
            })
            .then(function(response) {
              console.log(response);
            })
            .catch(function(error) {
              console.log(error);
            });
        }
    }
});

and my home.blade file like below


    <div id="new">
          <form class="form-horizontal" role="form" enctype="multipart/form-data" method="POST" v-on:submit.prevent="addPost">
          {{ csrf_field() }}
            <h4>@{{message}}</h4>
            <div class="form-group" style="padding:14px;">
              <textarea v-model="content" class="form-control" placeholder="Update your status"></textarea><br>
              <button class="btn btn-primary pull-right" type="submit">Post</button>
            </div>
          </form>
        </div>

data will added to database but it gives an error like csrf token not found

hemal left a reply on Error When Try To Add Something To Database Using Laravel And Vue

@aardalich I have change my routing now it gives a Internal server error like below

app.js:893 POST http://localhost:8000/addPost 500 (Internal Server Error)
Error: Request failed with status code 500
    at createError (app.js:918)
    at settle (app.js:41630)
    at XMLHttpRequest.handleLoad (app.js:792)

hemal started a new conversation Error When Try To Add Something To Database Using Laravel And Vue

my home.blade file like below

<div id="new">
          <form class="form-horizontal" role="form" enctype="multipart/form-data" method="POST" v-on:submit.prevent="addPost">
            <h4>@{{message}}</h4>
            <div class="form-group" style="padding:14px;">
              <textarea v-model="content" class="form-control" placeholder="Update your status">    </textarea><br>
              <button class="btn btn-primary pull-right" type="submit">Post</button>
            </div>
          </form>
        </div>

and my app.js in vue like below

const app = new Vue({
    el: '#new',
    data: {
        message: 'Update New Post:',
        content: '',
    },

    methods:{

        addPost(){
            axios.post('/home/addPost', {
              content: this.content
            })
            .then(function(response) {
              console.log(response);
            })
            .catch(function(error) {
              console.log(error);
            });
        }
    }
});

and i have create a route in web.php like below

Route::post('addPost', '[email protected]');

and controoler like below

public function addPost(Request $request) {

        $content = $request->content;

        $createpost = DB::table('post')
            ->insert(['content' => $content,
                'user_id' => Auth::user()->id,
                'status' => 0,

            ]);

    }

but in console it will give a error like below

app.js:11623 CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token

app.js:893 POST http://127.0.0.1:8000/home/addPost 404 (Not Found)
Error: Request failed with status code 404
    at createError (app.js:918)
        at settle (app.js:41630)
        at XMLHttpRequest.handleLoad (app.js:792)

How can I make this right

13 Oct
1 year ago

hemal started a new conversation When I Try Npm Run Watch Every Css, Js And Component Folder Get Removed?

Im try to work with vue but when i run that command every css and js will disapear How can I fix that

and

in app.js file if i use

const app = new Vue({ el: '#app', data : { msg:'first msg:' } }); and in view if use like below why its not showing the msg

@{{msg}}

hemal started a new conversation When I Try Npm Run Watch Every Css, Js And Component Folder Get Removed?

Im try to work with vue but when i run that command every css and js will disapear How can I fix that

and

in app.js file if i use

const app = new Vue({
        el: '#app',
        data : {
            msg:'first msg:'
        }
});

and in view if use like below why its not showing the msg

<div id="app">
        @{{msg}}
    </div>
10 Oct
1 year ago

hemal left a reply on How Can I Use Faker For Generate Details According To Registered User?

How can i do that can you help me with that

if I use

'user_id' => App\User::all()->random()->id,

It will get a random id but it will have more id for one user

hemal started a new conversation How Can I Use Faker For Generate Details According To Registered User?

Below code represent what I have done but it gives a error

$factory->define(App\User::class, function (Faker $faker) { static $password;

return [
    'name' => $faker->name,
    'email' => $faker->unique()->safeEmail,
    'gender' => $faker->boolean(),
    'password' => $password ?: $password = bcrypt('secret'),
    'slug' => $faker->username,
    'img' => 'boy.png',
    'remember_token' => str_random(10),
];

});

$factory->define(App\Profile::class, function (Faker $faker) { static $password;

return [
    'user_id' => App\User::all()->id(),
    'city' => $faker->city,
    'country' => $faker->country,
    'about' => $faker->paragraph(10),
    'remember_token' => str_random(10),
];

});

This is the error

[Exception] Property [id] does not exist on this collection instance.

How can I make this work

09 Oct
1 year ago

hemal left a reply on Why I Can't Get All Details According To User From Database?

Thanks @kfirba when I try that it gives a error like trying to get property of non-object

hemal started a new conversation Why I Can't Get All Details According To User From Database?

I have created a user table in database for user and profile table for more details model like below

Profile.php

public function user() { return $this->hasOne(User::class); } User.php

public function profile() { return $this->belongsTo(Profile::class); } When I call {{Auth::user()}} it only giving me the details in user table

How can i get all details