I am trying to insert the data in database while using Laravel. I am getting the error
BadMethodCallException Call to undefined method
App\AskQuestion::email()
While create.blade.php is my view and respones is the name of my table. The controller name is ResponesContoller and its code is given.
public function create()
{
abort_if(Gate::denies('respone_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$categories = Category::all()->pluck('name', 'id')->prepend(trans('Sélectionnez la thématique'), '');
$author_emails = User::all()->pluck('email', 'id')->prepend(trans('Choisissez votre email'), '');
$ask_questions = AskQuestion::all();
return view('admin.respones.create', compact('categories', 'author_emails', 'ask_questions'));
}
public function store(StoreResponeRequest $request)
{
$respone = Respone::create($request->all());
return redirect()->route('admin.respones.index')->with('success', 'Réponse enregistrée avec succès!');
}
public function edit(Respone $respone)
{
abort_if(Gate::denies('respone_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$categories = Category::all()->pluck('name', 'id')->prepend(trans('Sélectonnez la thématique'), '');
$author_emails = User::all()->pluck('email', 'id')->prepend(trans('Choisissez votre email'), '');
$ask_questions = AskQuestion::all()->pluck('text_question', 'id')->prepend(trans('Choisissez la question posée'), '');
$respone->load('category', 'author_email', 'ask_question');
return view('admin.respones.edit', compact('categories', 'author_emails', 'ask_questions', 'respone'));
}
The code of web.php is given and it works correctly, before I have checked as a test.
Please if anyone can help me!
Here was the problem i solve it.
public function created(Respone $model)
{
$data = ['action' => 'Une réponse est apportée à votre question!', 'model_name' => 'Respone',
'respone' => $model ];
$askQuestions = \App\AskQuestion::WhereHas('respones', function($q) {
return $q->where('objet_question', 'email', 'text_question');
})->get();
Notification::send($askQuestions, new ResponeEmailNotification($data));
}
Related
send an email in Laravel on a create function but not able to do
this is my store function
public function store()
{
$input = $request->all();
$user = \AUTH::guard()->user();
$input['created_by'] = $user->id;
\Log::info('$input'.json_encode([$input]));
$bulkLabSample = $this->bulkLabSampleRepository->create($input);
Flash::success(__('messages.saved', ['model' => __('models/bulkLabSamples.singular')]));
return redirect(route('bulkLabSamples.index'));
}
// use this
use Illuminate\Support\Facades\Mail;
// send mail via mail
Mail::send('your-view-blade', ['extraInfo' => $extraInfo], function ($message) {
$message->to('email#email.com');
$message->subject('your subject here');
});
By extraInfo you can pass values to the mail template as you want.
// for your code
public function store()
{
$input = $request->all();
$user = \AUTH::guard()->user();
$input['created_by'] = $user->id;
\Log::info('$input'.json_encode([$input]));
$bulkLabSample = $this->bulkLabSampleRepository->create($input);
Mail::send('your-view-blade', ['extraInfo' => $extraInfo], function ($message) {
$message->to('email#email.com');
$message->subject('your subject here');
});
Flash::success(__('messages.saved', ['model' => __('models/bulkLabSamples.singular')]));
return redirect(route('bulkLabSamples.index'));
}
after i added product data into database, this error page show me instead of routing to product page.
But, data is successful inserted.
ProductsController.php
public function store(Request $request)
{
$slug = $this->getSlug($request);
$dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();
// Check permission
$this->authorize('add', app($dataType->model_name));
// Validate fields with ajax
$val = $this->validateBread($request->all(), $dataType->addRows);
if ($val->fails()) {
return response()->json(['errors' => $val->messages()]);
}
if (!$request->ajax()) {
$requestNew = $request;
$requestNew['price'] = $request->price * 100;
$data = $this->insertUpdateData($requestNew, $slug, $dataType->addRows, new $dataType->model_name());
event(new BreadDataAdded($dataType, $data));
$this->updateProductCategories($request, $data->id);
return redirect()
->route("voyager.{$dataType->slug}.index")
->with([
'message' => __('voyager.generic.successfully_added_new')." {$dataType->display_name_singular}",
'alert-type' => 'success',
]);
}
}
Plz help me
This is database structure
This is API
Route::post('/friend', 'FriendController#index');
Route::post('/removerequest/{id}', 'FriendController#removerequest');
This is controller code which into friend request method and remove method, but error in remove friend method..
public function index(Request $request) {
$sender = Friend::where('sender_id', $request->sender_id)->where('receiver_id',$request->receiver_id)->first();
if(empty($sender)){
Friend::create(['sender_id'=>$request->sender_id,'receiver_id'=>$request->receiver_id, 'approved'=>'pending']);
$response = ['message'=>'Friend Request has been sent','status'=>200];
return response()->json($response);
}else{
$response = ['message'=>'Request has been sent already','status'=>200];
return response()->json($response);
}
}
public function removerequest($id){
$friends = Friend::all()
->where('receiver_id')
->where('sender_id')
->approved('accept')
->delete();
}
Error is
BadMethodCallException: Method Illuminate\Database\Eloquent\Collection::approved does not exist. in file /home/ynvih0l26evc/public_html/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php on line 104
enter code here
Update your Route to
Route::delete('/removerequest/{id}', 'FriendController#removerequest');
//change
->approve('approved', 'accept')
to
->where('approved', 'accept')
Update your controller method to
public function removerequest($id){
$friends = Friend::Find($id)->delete(); //see update here
//->where('receiver_id')
//->where('sender_id')
//->where('approved', 'accept')
//->delete();
}
OR
public function removerequest($id){
Friend::where( ['id' => $id, 'approved' => 'accept'])->delete();
}
I'm trying to send an email via Laravel that has table data attached to it and I'm having some trouble. Here is a snippet of the code I'm running:
public function pdfview(Request $request)
{
$items = DB::table("motor_vehicles")->get();
view()->share('vehicles', $items);
if ($request->has('download')) {
$pdf = PDF::loadView('pdfview');
$this->sendEmail();
return $pdf->download('pdfview.pdf');
}
return view('pdfview');
}
public function sendEmail()
{
Mail::send(['text' => 'mail'], $info, function ($message) {
$pdf = PDF::loadView('pdfview');
$message->to('inchiriseri#gmail.com', 'Itai Chiriseri')->subject('Sent Table Data');
$message->from('inchiriseri#gmail.com', 'Itai Chiriseri');
$message->attachData($pdf->output(), 'pdfview.pdf');
});
}
So all my other tests are working except this one when I test the view if it has this string or not. Problem is I'm getting an error message that the method being called is on null but is working when I access the page.
Error message:
Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getCode() on null
/home/vagrant/Code/team-stores/app/Http/Controllers/StoreManager/OrderTrackingController.php:20
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:55
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:44
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Route.php:203
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Route.php:160
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Router.php:574
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Router.php:576
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Router.php:535
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Router.php:513
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:174
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:149
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
/home/vagrant/Code/team-stores/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:234
/home/vagrant/Code/team-stores/tests/Feature/OrderTrackingTest.php:152
Test:
public function an_admin_can_view_all_orders_with_their_status()
{
$this->withoutMiddleWare();
StoreSession::setMyStore($this->store->code);
$orders = factory(CompletedOrder::class, 30)->create(['store_id' => $this->store->id]);
foreach ($orders as $order) {
factory(CompletedOrderItem::class, 5)->create(['completed_order_id' => $order->id]);
}
$response = $this->call("GET", route('list_completed_orders'));
foreach ($orders as $order) {
$response->assertSee($order->invoice()->getCode());
}
}
Controller:
public function index()
{
$store = StoreSession::getMyStore();
$completedOrders = CompletedOrder::where('store_id', $store->getId() )->get();
foreach ($completedOrders as $order) {
Log::info($order->invoice()->getCode());
}
return view('store-manager.order-tracking.index', compact('store', 'completedOrders'));
}
Thanks in advance.