My component in Vuejs isn't rendering in my Blade View - laravel

My Vuejs component isn't being rendered in my blade view. What am I doing wrong?
My component is called "star-rating".
Blade view
<div class="container">
<div class="row">
<div class="col-md-4">
**<star-rating></star-rating>**
</div>
<div class="col-md-4">
Rating - statistics
</div>
<div class="col-md-4">
#if(auth()->check())
<form method="post" action="{{ route('review.store') }}">
{{ csrf_field() }}
<h5>Form title</h5>
<div class="form-group">
<label for="headline"><strong>Headline</strong></label>
<input type="text" class="form-control" name="headline" id="headline" placeholder="Review title">
</div>
<div class="form-group">
<label for="headline"><strong>Rating</strong></label>
<input type="text" class="form-control" name="rating" id="rating" placeholder="A number from 1 - 5">
</div>
<div class="form-group">
<label for="headline"><strong>Description</strong></label>
<input type="text" class="form-control" name="description" id="description" placeholder="Tell us about your experience">
</div>
<input type="hidden" name="product_id" value="{{ $product->id }}">
<button class="btn btn-primary" type="submit">Save</button>
</form>
#else
Write a review
#endif
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-6">
<ul>
#forelse($product->reviews as $review)
<li>{{ $review->headline }}</li>
#empty
<h6>There are not reviews for this product</h6>
#endforelse
</ul>
</div>
</div>
</div>
#section('scripts')
<script src="{{asset('js/app.js')}}"></script>
#endsection
In the Vuejs, I have imported package for creating a rating system. If you would like to see the docs, are these Star Rating System Vuejs
Vuejs File
import VueStarRating from 'vue-star-rating'
require('./bootstrap');
window.Vue = require('vue');
Vue.component('example-component',
require('./components/ExampleComponent.vue'));
Vue.component('star-rating', VueStarRating);
const app = new Vue({
el: '#app'
});
I'm getting this two errors:
1) [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
2) CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token

1) Make sure you are compiling the script that you wrote in app.js with
npm run watch
command.
2) I dont see any div element which has #app id. You are saying that I will target #app element with
const app = new Vue({ <br>
el: '#app'
});
But you dont have any. Try to put it:
<div class="container" id="app">

The solution to my problem was solved in two steps:
1) run: npm run dev
2) run: npm run watch
Now, it works

Related

How to integrate inline-template with VueJS?

I have little problem with display info with VueJS in inline template.
I have 1 component only with scripts
Answer.vue
<script>
export default {
props: ['answer'],
data(){
return{
editing: false
}
}
}
</script>
I register in app.js
import { createApp } from 'vue';
require('./bootstrap');
require('./fontawesome');
let app=createApp({})
app.component('user-info', require('./components/UserInfo.vue').default);
app.component('answer', require('./components/Answer.vue'));
app.mount("#app")
and i want to implement in answer.blade.php
<answer :answer="{{$answer}}">
<div class="media post">
#include ('shared._vote', [
'model' => $answer
])
<div class="media-body">
{!! $answer->body_html !!}
<div class="row">
<div class="col-4">
<div class="ml-auto">
#can('update',$answer)
Edit
#endcan
#can('delete', $answer)
<form method="POST" class="form-delete" action="{{route("questions.answers.destroy", [$question->id,$answer->id])}}">
#method('DELETE')
#csrf
<button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure?')">Remove</button>
</form>
#endcan
</div>
</div>
<div class="col-4">
</div>
<div class="col-4">
<user-info :model="{{$answer}}" label="Answered"></user-info>
</div>
</div>
</div>
</div>
<hr>
</answer>
and i get this in console and this is answers which i cannot see:
https://prnt.sc/wof0gh
Thanks for help :)

Laravel: Browser is taking an eternity to load my project

i'm using Laravel 5.7 and WampServer to develop a project thats giving me a weird problem: it is taking an eternity to load up on my browser and I don't know whats going on. I have another Laravel project that works just fine but this one just crashed for one day to another. What can I do in order to fix this? I don't know where to start.
EDIT 1: I've commented the next component and my project runs fine. Either way, I can't see a problem in there. Can anybody help me with it?
<template>
<div class="card">
<div class="card-header text-center text-uppercase">{{ userEmailNotFound ? 'Ingresa tu correo electrónico' : 'Responde a la siguiente pregunta' }}</div>
<div class="card-body">
<div class="input-group mb-3" v-show="userEmailNotFound">
<div class="input-group-prepend">
<span class="input-group-text mdi mdi-email" id="email-addon"></span>
</div>
<input v-model="userEmail" name="email" type="email" class="form-control" id="email" placeholder="Correo electrónico" aria-describedby="email-addon" required>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios'
import swal2 from '../mixins/swal2'
// this.swalMixin('success', '¡Artículo creado!')
export default {
data() {
return {
userEmail: '',
userEmailNotFound: true
}
},
methods: {
//
}
}
</script>
<style lang="scss" scoped>
</style>
When I said "commented" i meant this:
#extends('layouts.app')
#section('content')
<div class="row justify-content-center">
<div class="col-md-6">
{{-- <question-password-component></question-password-component> --}}
</div>
</div>
#endsection

How Can i import Code ckeditor in my laravel app?

I am making a discussion forum application in Laravel . Here I want to use Ckeditor in comment sections. When somebody comments, then the code should show like here in stackoverflow.
#if(Auth::check()!=null)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel panel-body">
<form action="/comment" method="POST">
{{ csrf_field() }}
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="form-group">
<label for="comment">Reply</label>
<textarea name="body" class="form-control" style="size: 200px"></textarea>
</div>
<input type="submit" name="com" id="com" class="btn btn-xs btn-success pull-right">
</form>
</div>
</div>
</div>
#endif
Please give me very simple steps to use ckeditor. My master file is layout.app and this file is comment.blade.php. Please guide me where I should enter what files and scripts files.
You can use laravel CKEditor Package;
How to install:
Set up package
composer require unisharp/laravel-ckeditor
Add ServiceProvider
Edit config/app.php, add the following file to Application Service Providers section.
Unisharp\Ckeditor\ServiceProvider::class,
Publish the resources
php artisan vendor:publish --tag=ckeditor
Usage
Default way (initiate by name or id) :
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'article-ckeditor' );
</script>
Or if you want to initiate by jQuery selector :
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script src="/vendor/unisharp/laravel-ckeditor/adapters/jquery.js"></script>
<script>
$('textarea').ckeditor();
// $('.textarea').ckeditor(); // if class is prefered.
</script>
github link for more
Example:
#if(Auth::check()!=null)
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel panel-body">
<form action="/comment" method="POST">
{{ csrf_field() }}
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
<input type="hidden" name="post_id" value="{{ $post->id }}">
<div class="form-group">
<label for="comment">Reply</label>
<textarea id="editor1" name="body" class="form-control" style="size: 200px"></textarea>
</div>
<input type="submit" name="com" id="com" class="btn btn-xs btn-success pull-right">
</form>
</div>
</div>
</div>
#endif
<script>
$('.editor1').ckeditor(); // if class is prefered.
</script>
<script src="{{asset('vendor/unisharp/laravel-ckeditor/ckeditor.js')}}"></script>
<script src="{{asset('vendor/unisharp/laravel-ckeditor/adapters/jquery.js')}}"></script>
#section('script')
<script>
$('textarea').ckeditor();
</script>
#endsection
and i have provided editor id

Strange view error on Laravel

I have some cotroller like this:
Route::get('/article/create', 'ArticlesController#create');
and here's my ArticlesController#create:
public function create(){
return view('articles.create',
[
'title'=>'Add Artikel',
'username'=>'Whatever Myname',
'status' => 'Offline'
]
);
}
when i trying to access blog.dev/article/create i got this strange errors:
"Trying to get property of non-object (View: E:\xampp\htdocs\blog\resources\views\articles\single.blade.php)"
how come i can get this kind of error when my view is pointing at articles.create but the error is at single.blade.php which it suppose for ArticlesController#view?
this is what in create.blade.php:
#extends('admin.layout')
#section('content')
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Horizontal Form</h3>
</div>
#include('admin.formerrors')
<form method="post" class="form-horizontal" action="/articles">
{{ csrf_field() }}
<div class="box-body">
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input class="form-control" id="title" name="title" placeholder="Judul Artikel">
</div>
</div>
<div class="form-group">
<label for="content" class="col-sm-2 control-label">Content</label>
<div class="col-sm-10">
<textarea class="form-control" rows="3" id="content" name="content"></textarea>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
#endsection
and here's in my single.blade.php :
#extends('admin.layout')
#section('content')
<h1>{{ $article->title }}</h1>
<p>{{ $article->content }}</p>
<hr>
#foreach($article->comments as $comment)
<blockquote>
<p>{{ $comment->comment }}</p>
<small>{{ $comment->created_at->diffForHumans() }}</small>
</blockquote>
#endforeach
#include('admin.formerrors')
<form method="post" class="form-horizontal" action="/article/{{ $article->id }}/comment">
{{ csrf_field() }}
<div class="box-body">
<div class="form-group">
<label for="comment" class="col-sm-2 control-label">Comment</label>
<div class="col-sm-10">
<textarea class="form-control" rows="3" id="comment" name="comment"></textarea>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
#endsection
and here's my router:
Route::get('/articles', 'ArticlesController#index')->name('home');
Route::post('/articles', 'ArticlesController#save');
Route::get('/article/{id}', 'ArticlesController#view');
Route::get('/article/create', 'ArticlesController#create');
Route::post('/article/{article}/comment', 'CommentsController#save');
Route::get('/register', 'RegistrationController#create');
Route::post('/register', 'RegistrationController#store');
I try to change the create function by pointing into another view, but still it showing same error and pointing at single.blade view.
I delete all code at single.blade and write 'test' text, i don't get any errors. but i'm pointing my controller for viewing into create.blade not sigle.blade
After seeing you routes the problem is in this two routes :
Route::get('/article/{id}', 'ArticlesController#view');
Route::get('/article/create', 'ArticlesController#create');
In this case Laravel will consider the create in your path blog.dev/article/create as an id parameter of the view route here => /article/{id}.
So as a solution you should simply inverse the two routes :
Route::get('/article/create', 'ArticlesController#create');
Route::get('/article/{id}', 'ArticlesController#view');
You need to find what's in the file by reading more than just that line. Maybe you're including that file in the articles.create? Maybe you're accessing a variable that doesn't exist whenever you load the page. Edit your answer with more of the error and what's inside both blades and we can pinpoint what's wrong.

How to get Ckeditor textarea value in laravel

i am using Ckeditor for blog posting in my project when i submit the form nothing i am get in controller can any one suggest me solution for that.
my view is looking like
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Post</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('store-post') }}">
{{ csrf_field() }}
<div class="form-group">
<label for="category_id" class="col-md-2 control-label">Select Categories</label>
<div class="col-md-8">
<select class="form-control" id="category_id" name="category_id">
#foreach($categories as $category)
<option value="{{$category->url_name}}">
{{$category->category_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-2 control-label">Post Title</label>
<div class="col-md-8">
<input id="post_title" type="text" class="form-control" name="post_title" value="{{ old('post_title') }}">
</div>
</div>
<div class="form-group">
<label for="post_content" class="col-md-2 control-label">Post Description</label>
<div class="col-md-8">
<textarea id="post_content" rows="10" cols="60" class="span8" placeholder="Image Title Goes Here" name="post_content"></textarea>
</div>
</div>
<div class="form-group">
<label for="p_url" class="col-md-2 control-label">Post Url</label>
<div class="col-md-8">
<input id="p_url" type="text" class="form-control" name="p_url" value="{{ old('p_url') }}">
</div>
</div>
<div class="form-group">
<label for="p_title" class="col-md-2 control-label">Meta Title</label>
<div class="col-md-8">
<input id="p_title" type="text" class="form-control" name="p_title" value="{{ old('p_title') }}">
</div>
</div>
<div class="form-group">
<label for="p_keyword" class="col-md-2 control-label">Meta Keyword</label>
<div class="col-md-8">
<input id="p_keyword" type="text" class="form-control" name="p_keyword" value="{{ old('p_keyword') }}">
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-2 control-label">Meta Description</label>
<div class="col-md-8">
<textarea class="form-control" id="p_mdesc" name="p_mdesc" rows="3">
</textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-2">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</div>
<!--Error start-->
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<!--error ends-->
</form>
</div>
</div>
</div>
</div>
</div>
my controller code is
public function store(Request $request){
/*$this->validate($request, [
'category_id' => 'required',
'post_title' => 'required',
//'post_content' => 'required',
'p_url' => 'required',
'p_title' => 'required',
'p_keyword' => 'required',
'p_mdesc' => 'required',
]);*/
$post=new Post;
echo $post_content=$request->input('post_content');
}
in previous project ie designed in CI i just use
$tc=$this->input->post('tc'); in controller for getting the Ckeditor value but in laravel i am not sure how to get it done.
Your view contain 2 name attribute for the post_content field (textarea). Please check.
You can do it like this -
{!! Form::textarea('tc', $tc,array('required', 'class'=>'form-control', placeholder'=>'Your message')) !!}
and then you will have to initialise it
$(document).ready(function () {
CKEDITOR.replace( 'tc' );
});
The documentation has clear examples.
In your Blade you should add ckeditor like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A Simple Page with CKEditor</title>
<!-- Make sure the path to CKEditor is correct. -->
<script src="../ckeditor.js"></script>
</head>
<body>
<form>
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
</html>
So the javascript code triggers a replace of a textarea to the editor
Now for the retrieving data part
<script>
var data = CKEDITOR.instances.editor1.getData();
// Your code to save "data", usually through Ajax.
</script>
You need to create an endpoint if you want to send this data indeed trough Ajax. Don't forget to add a CSRF token
As mentioned by #user3888958,
<textarea name="tc" id="post_content" rows="10" cols="60"
class="span8" placeholder="Image Title Goes Here" name="post_content">
the textarea has two name attribute.
You could access the textarea content using the name attribute, remove any one name attribute and pass that in as a parameter to the request
$request->input('tc'); // OR
$request->input('post_content');
and to access the value of
<textarea class="form-control" id="p_mdesc" name="p_mdesc" rows="3">
</textarea>
you could access it using the name
$request->input('p_mdesc');

Resources