I'm setting up a map, and want to display the coordinates. What do I need to do?
Blade
#foreach($myArgans as $argan)
<div class="col-lg-12">
<h1>{{ $argan->titre }}</h2>
<img class="card-img-top" src="{{ asset('storage/'.$argan->image) }}">
<div style="text-align: justify">
{{ $argan->body }}
</div>
<div>
{{ $argan->getCoordinates() }}
</div>
</div>
#endforeach
Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use TCG\Voyager\Traits\Spatial;
class Argan extends Model
{
use Spatial;
protected $spatial = ['point'];
}
Related
I search to use x-slot in Livewire component to populate my sidebar with wire:model form inputs.
My edit.blade.php file:
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Header') }}
</h2>
</x-slot>
<div>{{ $sidebar }}</div>
<div class="bg-white">
<livewire:editor-component :post="$post" />
</div>
</x-app-layout>
My Livewire component:
<div>
<x-slot name="sidebar">
<div class="bg-gray-100">
Some text... Some inputs...
</div>
</x-slot>
<div class="p-5">
<livewire:other-component />
</div>
</div>
And my component:
<?php
namespace App\Http\Livewire;
use App\Models\Post;
use Livewire\Component;
class EditorComponent extends Component
{
/** #var Post */
public $post;
}
I want access to $post in sidebar x-slot and I should be able to write in input and manage values of component from sidebar.
You can access $post inside your Livewire view directly as it is a public property.
As example you can output the id of your $post, given that there is an id property on your $post, like this:
<div>
<x-slot name="sidebar">
<div class="bg-gray-100">
Some text... Some inputs...
</div>
</x-slot>
Post id: {{ $post->id }}
<div class="p-5">
<livewire:other-component />
</div>
</div>
How to access properties is written down in the Livewire docs
Access properties across components, can be done by utilizing Livewire Events
I had a problem while trying out the recently released laravel 8, I'm trying to find out what the changes are and how it works. When I did that I had a problem with the paginate laravel 8 UI getting messy and somehow it happened. Is there anyone who can help me? or have experienced the same thing?
Like this the view I got in laravel 8
Laravel 8 paginate UI
and this is the code I use "Index.blade.php"
#extends('layouts.app')
#section('title', 'Post')
#section('contents')
<div class="container">
<div class="row">
#foreach ($posts as $post)
<div class="col-md-4 mb-4">
<div class="row">
<div class="card mb-4">
<div class="card-header">
{{ $post->title }}
</div>
<div class="card-body">
{{ $post->body }}
</div>
<div class="card-footer">
{{ $post->created_at->diffForHumans() }}
</div>
</div>
</div>
</div>
#endforeach
</div>
<div class="d-felx justify-content-center">
{{ $posts->links() }}
</div>
</div>
#endsection
the code I use for PostController
<?php
namespace App\Http\Controllers;
use App\Models\Posts;
use Illuminate\Http\Request;
class PostsController extends Controller
{
public function index()
{
$posts = Posts::latest()->paginate(6);
// dd($post);
return view('post.index', compact('posts'));
}
}
just make sure you have this in your AppServiceProvider.
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::useBootstrap();
}
and you're good to go.
I tried doing adding the Paginator::useBootstrap(); in the AppServiceProvider.php but it didn't work.
But this worked:
// Directly in your blade file
$posts->links('pagination::bootstrap-4')
First go to the file app\Providers\AppServiceProvider.php and add:
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::useBootstrap();
}
Use this after #endforeach in your post.blade.php:
{{ $blogs->links() }}
Don't use this way:
$posts->links('pagination::bootstrap-4')in AppServiceProvider.php
Right way :
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::useBootstrap();
}
Then in any blade, you want to use pagination like this:
{{ $posts->links() }}
i want to create some CMS project with the laravel, when the user trying to click the categories, the app will show the post that only shows the category that user clicked. When the user click the categories, the app says error Bad Method Call. What should i do? Any help will be appreciated.
Here's the code from web.php
<?php
use App\Http\Controllers\Blog\PostsController;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', 'WelcomeController#index')->name('welcome');
Route::get('blog/posts/{post}', [PostsController::class, 'show'])->name('blog.show');
Route::get('blog/categories/{category}', [PostsController::class, 'category'])->name('blog.category');
Route::get('blog/tags/{tag}', [PostsController::class, 'tag'])->name('blog.tag');
Auth::routes();
Route::middleware(['auth'])->group(function () {
Route::get('/home', 'HomeController#index')->name('home');
Route::resource('categories', 'CategoriesController');
Route::resource('posts','PostsController');
Route::resource('tags','TagsController');
Route::get('trashed-posts','PostsController#trashed')->name('trashed-posts.index');
Route::put('restore-post/{post}', 'PostsController#restore')->name('restore-posts');
});
Route::middleware(['auth', 'admin'])->group(function () {
Route::get('users/profile', 'UserController#edit')->name('users.edit-profile');
Route::put('users/profile', 'UserController#update')->name('users.update-profile');
Route::get('users','UserController#index')->name('users.index');
Route::post('users/{user}/make-admin', 'UserController#makeAdmin')->name('users.make-admin');
});
Here's the code from PostsController.php
<?php
namespace App\Http\Controllers\Blog;
use App\Http\Controllers\Controller;
use App\Post;
use Illuminate\Http\Request;
use App\Tag;
use App\Category;
class PostsController extends Controller
{
public function show(Post $post) {
return view('blog.show')->with('post', $post);
}
public function category(Category $category) {
return view('blog.category')
->with('category', $category)
->with('posts', $category->posts()->simplePaginate())
->with('categories', Category::all())
->with('tags', Tag::all());
}
public function tag(Tag $tag) {
return view('blog.tag')
->with('tag', $tag)
->with('posts', $tag->posts()->simplePaginate(3));
}
}
Here's the code from App\Category.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $fillable = ['name'];
public function post() {
return $this->hasMany(Post::class);
}
}
Here's the code from category.blade.php
#extends('layouts.blog')
#section('title')
Category {{ $category->name }}
#endsection
#section('header')
<header class="header text-center text-white" style="background-image: linear-gradient(-225deg, #5D9FFF 0%, #B8DCFF 48%, #6BBBFF 100%);">
<div class="container">
<div class="row">
<div class="col-md-8 mx-auto">
<h1>{{ $category->name }}</h1>
<p class="lead-2 opacity-90 mt-6">Read and get updated on how we progress</p>
</div>
</div>
</div>
</header><!-- /.header -->
#endsection
#section('content')
<main class="main-content">
<div class="section bg-gray">
<div class="container">
<div class="row">
<div class="col-md-8 col-xl-9">
<div class="row gap-y">
#forelse($posts as $post)
<div class="col-md-6">
<div class="card border hover-shadow-6 mb-6 d-block">
<img class="card-img-top" src="{{ asset($post->image) }}" alt="Card image cap">
<div class="p-6 text-center">
<p>
<a class="small-5 text-lighter text-uppercase ls-2 fw-400" href="#"></a>
{{ $post->category->name }}
</p>
<h5 class="mb-0">
<a class="text-dark" href="{{ route('blog.show',$post->id) }}">
{{ $post->title }}
</a>
</h5>
</div>
</div>
</div>
#empty
<p class="text-center">
No Results found for query <strong>{{ request()->query('search') }} </strong>
</p>
#endforelse
</div>
{{-- <nav class="flexbox mt-30">
<a class="btn btn-white disabled"><i class="ti-arrow-left fs-9 mr-4"></i> Newer</a>
<a class="btn btn-white" href="#">Older <i class="ti-arrow-right fs-9 ml-4"></i></a>
</nav> --}}
{{ $posts->appends(['search' => request()->query('search') ])->links() }}
</div>
#include('partials.sidebar')
</div>
</div>
</div>
</main>
#endsection
If you guys didn't see which file that i don't show up, just ask,.
If you guys see any problems that confusing, i can use teamviewer.
Any Help will be appreciated.
Thank you.
The error told that you don't have posts. Indeed it is. What you have is post() method on Category class, as evidently seen in this line:
public function post() {
You should change this ->with('posts', $category->posts()->simplePaginate()) to be:
public function category(Category $category) {
return view('blog.category')
->with('category', $category)
->with('posts', $category->post()->simplePaginate())
->with('categories', Category::all())
->with('tags', Tag::all());
}
In your model, you defined a post relationship whereas you use a posts relationship then, they're not the same one. You should replace post by posts because it's a to-many relationship.
Your relationship is post and you have multiple ->with('posts', $category->posts()->simplePaginate()). Can you change those to ->with('post') and try again?
i'm getting this error while passing data from controller to blade, every things looks good for me but i don't know what i'm missing
ErrorException in 3f66fc6a06d60b9d9b9d521f50ebd1074b04f3bc.php line 228:
Undefined variable: users (View: C:\wamp\www\transport_mithra\resources\views\agents.blade.php)
My controller is
<?php
namespace App\Http\Controllers;
use Response;
use Session;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
class UsersController extends ApiController
{
public function index()
{
$users = User::all();
return View('agents', compact($users));
//return view('agents')->with('users', $users); with this is also same error
}
}
and my agents.blade.php
#foreach ($users as $agent)
<div class="col s12 m6 l3">
<div class="card small card-agent">
<div class="card-image">
<img src="assets/images/profile-image-2.png" alt="">
</div>
<div class="card-content">
<div class="card-details">
<p>Name:</p><span>{{ $agent->name }}</span>
</div>
<div class="card-details">
<p>Phone:</p><span>{{ $agent->phone_number }}</span>
</div>
<div class="card-details">
<p>Email:</p><span>{{ $agent->email }}</span>
</div>
<div class="card-details">
<p>Address:</p><span>{{ $agent->address_city_village }}</span>
</div>
</div>
<div class="card-action">
<p>Drivers: 502</p>
View
</div>
</div>
</div>
#endforeach
looking forward for much needed help
Thank you
You should use correct syntax:
return view('agents', compact('users'));
compact('users') is the same as ['users' => $users]
Also the following will work:
return view('agents')->with(['users' => $users]);
I'm laravel begginer and I wan't to make simple CMS. Ok, so i have simple question:
I want when click on avatar (profile image) - redirect to user profile (http://example.com/profiles/nickname/id)
In DB it saves that:
as you see author_id I have, now I need to get author name from users table:
And then generate url: http://example.com/profiles/Evaldas/2 (Evaldas, because author_id is 2 in topics table)
My routes file:
Route::get('topic/{tname}/{tid}', 'viewTopic#showTopic');
My viewTopic.php Controller:
<?php
namespace App\Http\Controllers;
use DB;
use View;
class viewTopic extends Controller
{
public function showTopic($tname, $tid)
{
return View::make('posts', [
'topics' => DB::table('topics')
->where('id', $tid)
->where('seo_title', $tname)
->first(),
'posts' => DB::table('posts')
->where('topic_id', $tid)
->select()
->get()
]);
}
}
And layout:
#extends('layouts.main')
#section('content')
<div class="media">
<div class="media-left">
<a href="HERE MUST BE HREF TO PROFILE">
<img class="media-object" src="http://localhost/uploads/avatars/2.jpg" style="width: 64px">
</a>
</div>
<div class="media-body" rel="#author{{ $topics->author_id }}">
<h4 class="media-heading">{{ $topics->title }}</h4>
#if(!empty($topics->text))
{{ $topics->text }}
#else
Message empty :(
#endif
</div>
#foreach($posts as $post)
<div class="media">
<div class="media-left">
<a href="HERE MUST BE HREF TO PROFILE">
<img class="media-object" src="http://localhost/uploads/avatars/1.png" style="width: 64px">
</a>
</div>
<div class="media-body" rel="#post{{ $post->pid }}">
{{ $post->text }}
</div>
</div>
#endforeach
</div>
#stop
Thanks in advance ;)
You could use the User object to look it up ... but a better option would be to join the 'posts' table to the 'user' table, and select it from the results - have a look at http://laravel.com/docs/5.1/queries#joins