Databases not linking using hasMany in laravel - php

I am trying to use data from two databases in laravel. Edit: I have added the products controller to the bottom of this post
This is how I test if they are linked:
<p>TEST :{{ $products->ticket->created_at}}</p>
error message:
Undefined variable: products (View: /Applications/MAMP/htdocs/lsapp/resources/views/products/create.blade.php)
Product.php (App)
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
//Table NAME
protected $table = 'products';
//PRIMARY KEY
public $primaryKey = 'id';
//Timestamps
public $timestamps =true;
public function user(){
return $this->belongsTo('App\User');
}
public function products()
{
return $this->hasMany(App\product::class);
}
}
Ticket.php (app)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class product extends Model
{
public function Product(){
return $this->belongsTo(App\Product::class);
}
}
Product Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\product;
use App\Ticket;
class productController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth',['except' => ['index','show']]);
}
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$products = product::orderBy('created_at','desc')->paginate(10);
//$products = product::where('type','major')->get();
return view('products.index')->with('products',$products);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('products.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request,[
'title' => 'required',
]);
//create product
$product = new product;
$product->title = $request->input('title');
$product->venue = $request->input('venue');
$product->city = $request->input('city');
$product->country = $request->input('country');
$product->description = $request->input('description');
$product->date = $request->input('date');
$product->user_id = auth()->user()->id;
$product->save();
return redirect('/products')->with('success','product Created');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$product = product::find($id);
return view('products.show')->with('product',$product);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$product = product::find($id);
if(auth()->user()->id !==$product->user_id){
return redirect('/products')->with('error','unauthorised page');
}
return view('products.edit')->with('product',$product);
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'title' => 'required'
]);
$product = product::find($id);
$product->title = $request->input('title');
$product->venue = $request->input('venue');
$product->city = $request->input('city');
$product->country = $request->input('country');
$product->description = $request->input('description');
$product->date = $request->input('date');
$product->user_id = auth()->user()->id;
$product->save();
return redirect('/products')->with('success','product updated');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$product = product::find($id);
if(auth()->user()->id !==$product->user_id){
return redirect('/products')->with('error','unauthorised page');
}
$product->delete();
return redirect('/products')->with('success','product deleted');
}
}

There are a few problems with your code.
<p>TEST :{{ $products->ticket->created_at}}</p> will never work.
Assuming you are testing in your index page, you need to loop over each product in order to see it's relationship with a ticket.
Do all of your products have a single ticket? If so, then you can just define the single ticket in a config variable. It does not make sense to define a many-to-one relationship in a database.
In your Product model, you have not defined a relationship to the Ticket model. You only have a relationship defined in the Ticket model to the Product model. This means that you can access a product from the ticket, but not the other way around. You need to explicitly define a one-on-one relationship from Product to Ticket in order to use it.
You have defined this function within the Product model.
public function products() {
return $this->hasMany(App\product::class);
}
Why? Do products themselves have many products? I think you may benefit from learning about eloquent relationships. Laracasts is a good resource for learning Laravel from scratch.
Also see Laravel official Eloquent documentation

Related

New blogs not being shown or stored in the database

Once I delete a blog, it is deleted completely. I can make a new one, but it does not show on the website or in the database. This is my BlogController:
<?php
namespace App\Http\Controllers;
use App\Models\Blog;
use Illuminate\Http\Request;
class BlogController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$blog = Blog::paginate(5);
return view('blogs.index', compact('blog'))
->with('i',(request()->input('page',1)-1)*5);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('blogs.create');
Blog::create($request->all());
return redirect()->route('blogs.index')
->with('success','Blog created successfully.');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'title' => 'required',
'description' => 'required',
]);
$blog = new Blog;
$blog->title = $request->title;
$blog->description = $request->description;
$blog->save();
return redirect()->route('blogs.index');
}
/**
* Display the specified resource.
*
* #param \App\Blog $blog
* #return \Illuminate\Http\Response
*/
public function show(Blog $blog)
{
return view('blogs.show', compact('blog'));
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Blog $blog
* #return \Illuminate\Http\Response
*/
public function edit(Blog $blog)
{
return view('blogs.edit', compact('blog'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Blog $blog
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Blog $blog)
{
$request->validate([
'title' => 'required',
'description' => 'required',
]);
// $blog->title = $request->title;
// $blog->description = $request->description;
$blog->fill($request);
// dd($blog);
return redirect()->route('blogs.index')
->with('success','Blog updated successfully');
}
/**
* Remove the specified resource from storage.
*
* #param \App\Blog $blog
* #return \Illuminate\Http\Response
*/
public function destroy(Blog $blog)
{
$blog->delete();
return redirect()->route('blogs.index')
->with('success','Blog deleted successfully');
}
}
And the problem is apparently the 103th line, public function update: $blog->fill($request); It does not store in the database nor is it visible on the webpage/blog. I tried deleting that specific line, but it is the same. Nothing changes. I do not understand what the issue could be. Can someone help?
1ST OPTION In order for the fill method to work, you must call $blog->save() after that.
$blog->fill($request);
$blog->save();
Also when you use fill method you are mass assigning values. By default Laravel protects you from mass assigning fields.
Open your Blog.php model and add the fields you want to mass assign to the array $fillable
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'title',
'description',
];
2ND OPTION is to use the update method (don't forget to also add fields in $fillable in the model from 1st option since update method is also mass assigning fields):
$blog->update($request);
3RD OPTION manually assign each field one-by-one just like you did in the store method:
$blog->title = $request->title;
$blog->description = $request->description;
$blog->save();
The fill function dose not update data in database.
This function only assignment value to attribute in protected $fillable = ['title','description']; in Blog model.
Using update function to update data to database.
$blog->fill($request);
$blog->update();

Laravel Nova doesn't find some Models

With some Models, when I make a new Nova Resource for them, seems that Nova can't find the Model because they doesn't show on sidebar (i can't reach them also by URL, giving me a 404).
But this happens only for specific Models and if I try to modify the target Model in the Resource with another one (editing the $model variable), it works and shows the Resource in the sidebar (but with the wrong model). Nova isn't throwing me any error so the debugging is getting crazy difficult.
The Models that doesn't work in my project are named "Product" and "Company".
I'm using Laravel 7.28.3, Nova 3.9.1, MariaDB 10.4.11 and PHP 7.4.1 with Homestead.
Here's the code of Product resource:
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
class Product extends Resource
{
/**
* The model the resource corresponds to.
*
* #var string
*/
public static $model = \App\Product::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* #var string
*/
public static $title = 'title';
/**
* The columns that should be searched.
*
* #var array
*/
public static $search = [
'id', 'name'
];
/**
* Get the fields displayed by the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
];
}
/**
* Get the cards available for the request.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
public function actions(Request $request)
{
return [];
}
}
And here's the Model code:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Product extends Model implements HasMedia
{
use InteractsWithMedia;
public function visits()
{
return visits($this);
}
public function user() {
return $this->belongsTo('App\User');
}
public function company() {
return $this->belongsTo('App\Company');
}
public function productVariety() {
return $this->belongsTo('App\ProductVariety', 'product_variety_id');
}
public function productSpecies() {
return $this->belongsTo('App\ProductSpecies', 'product_species_id');
}
public function productNutrients() {
return $this->hasMany('App\ProductNutrient');
}
public function baseProduct() {
return $this->hasOne('App\Product', 'base_product_id');
}
public function recipes() {
return $this->hasMany('App\Recipe', 'base_product_id');
}
protected $fillable = [
'user_id', 'company_id', 'imageline_id', 'products_species_id', 'products_varieties_id', 'base_product_id',
'name', 'scientific_name', 'production_start', 'production_end', 'production_city', 'description', 'story', 'curiosities', 'advices', 'quantity_advices', 'why_good', 'who_good',
'is_base_product', 'show_related_recipes', 'show_related_products'
];
}
Check your AuthServiceProvider on app/Providers/AuthServiceProvider.php if there is a Policy set to this model. Then on your policy class (probably ProductPolicy which is bind to Product model, check view and viewAny methods, these methods must return true or conditional true.

Trying to get property of a non-object problem in laravel

I am working on a laravel project. In this project, if a non-user tries to edit a post then it will redirect to the posts page without letting the user make any edit. But I am getting this error
Trying to get property of non-object (View: C:\xampp\htdocs\lsapp\resources\views\posts\show.blade.php).
ErrorException (E_ERROR) Trying to get property of non-object (View: C:\xampp\htdocs\lsapp\resources\views\posts\show.blade.php) Previous exceptions and may be it might help Trying to get property of non-object (0) ErrorException {#221 ▼ #message: "Trying to get property of non-object" #code: 0 #file: "C:\xampp\htdocs\lsapp\storage\framework\views\b4b78b7a31531d4e8ddf98112cc09d54ba62ed99.php" #line: 3 #severity: E_NOTICE }
Here is the edit code:
public function edit($id)
{
$post = Post::find($id);
if(auth()->user()->id !== $post->user_id){
return redirect ('posts')->with('error','Unauthorized page');
}
return view('posts.edit')->with('post',$post);
}
PostsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use DB;
class PostsController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth',['except'=>['index','show']]);
}
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
//$posts=Post::all();
//$posts=Post::orderBy('title','desc')->get();
//return Post::where('title','post two')->get();
//$posts=DB::select("SELECT * FROM posts");
//$posts= Post::orderBy('title','desc')->take(1)->get();
$posts= Post::orderBy('created_at','desc')->paginate(1);
return view('posts.index')->with('posts',$posts);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('posts.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request,[
'title'=>'required',
'body'=>'required'
]);
//Create posts
$post=new Post;
$post->title = $request->input('title');
$post->body = $request->input('body');
$post->user_id=auth()->user()->id;
$post->save();
return redirect('posts')->with('success','Post Created');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$post = Post::find($id);
return view('posts.show')->with('post',$post);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$post = Post::find($id);
if(auth()->user()->id !== $post->user_id){
return redirect ('posts')->with('error','Unauthorized page');
}
return view('posts.edit')->with('post',$post);
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request,[
'title'=>'required',
'body'=>'required'
]);
//Create posts
$post=Post::find($id);
$post->title = $request->input('title');
$post->body = $request->input('body');
$post->save();
return redirect('posts')->with('success','Post Updated');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$post=Post::find($id);
$post->delete();
return redirect('posts')->with('success','Post Deleted');
}
}
show.blade.php:
#extends('layouts.app')
#section('content')
Back
<h1>{{$post->title}}</h1>
<div>
{{$post->body}}
</div>
<hr>
#if(!Auth::guest())
#if(Auth::user()->id==$post->user_id)
<small>Witten on {{$post->created_at}} by {{$post->user->name}}</small>
<hr>
Edit
{!!Form::open(['action'=>['PostsController#destroy',$post->id],'method'=>'POST', 'class'=>'pull-right'])!!}
{{Form::hidden('_method','DELETE')}}
{{Form::submit('Delete',['class'=>'btn btn-danger'])}}
{!!Form::close()!!}
#endif
#endif
#endsection
here is my route:
Route::get('/index', 'PagesController#index');
Route::get('/about', 'PagesController#about');
Route::get('/services', 'PagesController#services');
Route::resource('/posts','PostsController');
Auth::routes();
Route::get('/dashboard', 'DashboardController#index');
Here is user.php in case it helps
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function posts(){
return $this->hasMany('App\Post');
}
}
Look in your blade file. Whenever you all $post->user->SOMEPROPERTIES, change it to $post->user['SOMEPROPERTIES']
Example:
<small>Witten on {{$post->created_at}} by {{$post->user['name']}}</small>
I hope it will work for you. (Working in my case)
Look in your blade file.
Whenever you all $post->user->SOMEPROPERTIES, change it to $post->user()
like here:
<small>Witten on {{$post->created_at}} by {{$post->user()->name}}</small>
check your href value. Check the curly braces
Wrong code:
#foreach($posts as $post)
the text of the link
#endforeach
Working code:
#foreach($posts as $post)
the text of the link
#endforeach
I hope this helps in some way.

Laravel 6 Error - Illuminate\Contracts\Container\BindingResolutionException Target class does not exist

I am trying to insert data into my database but this error shows up:
Illuminate\Contracts\Container\BindingResolutionException Target class
[App\Http\Controllers\Master\Request] does not exist.
Though my Vendor Model and VendorController is in right directory.
Here's my Vendor Model source code (\app\Model\Master):
<?php
namespace App\Model\Master;
use Illuminate\Database\Eloquent\Model;
class Vendor extends Model
{
protected $table = 'vendors';
public function user_modify()
{
return $this->belongsTo('\App\User', 'user_modified');
}
}
Here's my VendorController source code (\app\Http\Controllers\Master):
<?php
namespace App\Http\Controllers\Master;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
class VendorController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view("vendor.index");
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view("vendor.create");
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data = new Vendor();
$data->vendor_firstname = $request->first_name;
$data->vendor_lastname = $request->last_name;
$data->vendor_address = $request->address;
$data->vendor_phone = $request->contact;
$data->vendor_firstname = $request->first_name;
$data->active = $request->vendor_status;
$data->vendor_modified = Auth::user()->id;
if($data->save()){
return redirect()->route('vendor.index');
}else{
return redirect()->back();
}
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
And here's my route list:
What causes this error? And how do I fix it? tried running php artisan
config:cache and composer dump-autoload but still no luck..
Add use Illuminate\Http\Request; In your Controller File.
<?php
namespace App\Http\Controllers\Master;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
class VendorController extends Controller
{
public function index()
{
return view("vendor.index");
}
public function create()
{
return view("vendor.create");
}
public function store(Request $request)
{
$data = new Vendor();
$data->vendor_firstname = $request->first_name;
$data->vendor_lastname = $request->last_name;
$data->vendor_address = $request->address;
$data->vendor_phone = $request->contact;
$data->vendor_firstname = $request->first_name;
$data->active = $request->vendor_status;
$data->vendor_modified = Auth::user()->id;
if($data->save()){
return redirect()->route('vendor.index');
}else{
return redirect()->back();
}
}
}

laravel route and controller

i am a new laravel user and a have admin page which doing update delete and insert my problem is i dont know how to call this functions in route.
Note: all this options working on one page (admin).
so please can anyone help me ?!
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
class BlogPostController extends Controller
{
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index(){
$date = date('Y-m-d');
$time = time('H:i:s');
/*$sections = ['History' => 'history.png','Electronics' => 'electronics.png','Electrical' => 'electrical.png','Science' => 'science.png',
'Art'=>'ARt.png','Database'=>'database.png','Irrigation'=>'irrigation.png','Novel'=>'Novel.png','Style'=>'Stsyle.png'];
*/
$sections = DB ::table('sections')->get();
return view('libraryViewsContainer.library')->withSections($sections)->withDate($date)->withTime($time);
}
/**
* Show the form for creating a new resource.
*
* #return Response
*/
public function create(){
//return View::make('posts.create');
return '<center><h1>Creating new section in the library!</h1></center>';
}
/**
* Store a newly created resource in storage.
*
* #return Response
*/
public function store( Request $request){
$section_name = $request->input('section_name');
$file = $request->file('image');
$destinationPath = 'images';
$filename = $file->getClientOriginalName();
$file->move($destinationPath,$filename);
DB ::table('sections')->insert(['section_name'=>$section_name,'image_name'=>$filename]);
return redirect('admin');
}
/**
* Display the specified resource.
*
* #param int $id
* #return Response
*/
public function show($id){
// $post = Post::find($id);
// return View::make('posts.show')->with('post', $post);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return Response
*/
public function edit($id){
// $post = Post::find($id);
// return View::make('posts.edit')->with('post', $post);
}
/**
* Update the specified resource in storage.
*
* #param int $id
* #return Response
*/
public function update($id,Request $request){
$section_name = $request->input('section_name');
DB ::table('sections')->where('id',$id)->update(['section_name'=>$section_name]);
return redirect('admin');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return Response
*/
public function destroy($id){
DB :: table('sections')->where('id',$id)->delete();
return redirect('admin');
}
public function admin()
{
$sections = DB ::table('sections')->get();
return view('libraryViewsContainer.admin',['sections'=>$sections]);
}
}
Not entirely sure of the question, but you list the routes in routes.php, under the web group (so it applies default checks).
When you have resources, they'll use CRUD operations (create, read, update, delete) and will correspond to the default operates in the class. Else, make your own function names, and put seperate routes.
Route::group(['middleware' => ['web', 'auth']], function () {
Route::resource('/user', 'UserController');
}
Another option is calling the method direct in your routes:
Route::get('/auth/login', '\App\Http\Controllers\Auth\AuthController#getLogin');
Route::any('/datafeed/{id}/validate', 'DataFeedController#validateQuery');
You'll notice {id} which is the variable available in the function you've selected i.e. function validateQuery($id);
Here's a full example:
class UserController extends BaseController
{
public function __construct(User $model)
{
parent::__construct($model);
}
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$collection = $this->model->all();
return view('user.index')->with('collection', $collection);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('user.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$input = Input::except(['_method', '_token']);
$connector = $this->model->create($input);
return redirect()->action('UserController#show', [$connector->id]);
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
$connector = $this->model->findOrFail($id);
return view('user.show')->with('connector', $connector);
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$connector = $this->model->findOrFail($id);
return view('user.edit')->with('connector', $connector);
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$input = Input::except(['_method', '_token']);
$connector = $this->model->findOrFail($id);
$connector->update($input);
return redirect()->action('UserController#show', [$id]);
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$currentID = Auth::user();
$user = $this->model->findOrFail($id);
if ($currentID->id != $user->id) {
$user->delete();
} else {
Session::flash('flash_message', "You cant delete your own account!");
Session::flash('flash_type', 'alert-danger');
}
return redirect()->action('UserController#index');
}
And another example with a custom route:
Route::any('/datafeed/{id}/execute', 'DataFeedController#execute');
public function execute($id, $test = false) {
$results = $this->executeQuery($id, $test);
return view('datafeed.execute')->with('results', $results);
}
I'm not entirely sure on your plans (or even if you've fully read the documentation?) but you can access these functions by doing something similar to the following in your routes.php or Routes\web.php (depending on your version) file:
Route::get('/blog/create', 'BlogPostController#create');
Route::get('/blog/article/{id}', 'BlogPostController#show');
The first part is defining the route and the second part is saying what method should be run on the defined controller when this route is matched in the address bar. It doesn't always have to be get requests though, you can do get, post, patch and put

Categories