Dingo APi error message - laravel

I am trying to render my mailable in the browser in order to check the content. However I'm getting this message {"message":"sha1() expects parameter 1 to be string, object given","status_code":500}
My code snippet
I am running Dingo/Api on my page as well an I think it's somehow connected with it.
Can you please give me the suggestion why am I getting this message instead of rendering mailable?
Thank you

We got this to work by assigning the mailable to a var first and then directly calling the render function on it, like so:
$mailable = new YourMailableName();
return $mailable->render();

Related

laravel taking data with input function

i want to take data with input function in Laravel controller.
When i write dd($request->data) im getting this:
"_token=R58UyxNckoaiL0eFSIsd434343Gsh&name_surname=sdfsadf&telephone=0505"
I want to take name_surname
I tried this code
$request->data->input('name_surname')
but i can not get any data. its turning null. How can i get datas. If you help me i will be glad
you can access data sent from a form using $reqeust object using $request->input_name
so, to take name_surname and telephone
$name_surname = $req->name_surname;
$telephone = $req->telephone;
learn more from laravel doc(https://laravel.com/docs/8.x/requests#retrieving-input-via-dynamic-properties)
Also, validate user inputs before do anything
Try this code to make sure what are the inputs fields your are receiving and make sure input fields names
dd($request->all())
then try this
$request->field_name

Can I process my response right before I send it to the client in Laravel 4.2?

I want to parse and do changes to the HTML I want to send to the client, right before it's sent.
I figured out I could use the App::after filter, which exposes both the response and request objects to me but then I got stuck...
I want to somehow get the HTML from the response, parse it, change it and send the changed HTML to the client instead but cannot find any properties/methods I can use in the response object.
Calling dd($response) crashes my browser and cannot find anything related in the Laravel website...
Does anyone know how/if what I want to do is possible?
Looks like all I had to do was use the getContent and setContent methods of the $response object.
So my filter now looks something like this:
App::after(function($request, $response){
$html = $response->getContent();
$html = Helpers::transformHtml($html);
$response->setContent($html);
});

Magento sent custom message after indexController is done

I've got a module, it works fine and the indexcontroller handles all the things I want it to.
And it ends with: $this->_redirect('adminhtml/sales_order/');
Now my question is: how can I sent a message with this redirect? So that a 'complete' message shows up on top of the screen?
I've tried this: $this->_redirect('adminhtml/sales_order/')->addSuccess("Done!"); but that doesn't work...
addSuccess() is a method of the session model (technically the messages get stored in the session and retrieved on the next page)
So your code has to be something like that:
Mage::getSingleton('adminhtml/session')->addSuccess('Done!');
$this->_redirect('adminhtml/sales_order');
try this
Mage::getSingleton('adminhtml/session')->addSuccess('Done....');
$this->_redirect('adminhtml/sales_order/')
HTH

If codeigniter model returns 0 rows, display custom error message. How to extend to a general case?

I have a variety of functions within my models which serve a different purpose.
One for example looks up the data for a given $_GET variable in the URL string.
I am trying to work out a way of displaying an error message if there is no matching row in the database due to url string manipulation for example.
My first idea was simply to return an error message (if there is an error) with each call to the function, then simply have an if statement whereby if there is an error, an error view is shown, and if not the normal view is shown..
Problem with this is that this function is called numerous times in my controller, and other similar functions are called throughout my code which need similar error handling..
I dont want millions of similar if/else statements all over my code to handle errors..
Anyone got any better ideas?
Cheers
Use the flashdata item of the session class. You can concatenate error messages and put them in the flashdata item to display.
my_function(){
// code that determines if there is an error returns => $error
if ($error)
{
// concat previous and current errors
$new_error = $this->session->flashdata('errors') . $error;
// replace 'errors' with newly concatenated errors
$this->session->set_flashdata('errors', $new_error);
}
}
This will keep track of all errors generated through each request and allow you to display a "list" of errors for that particular request.
echo $this->session->flashdata('errors');

Callbacks on Ajax.BeginForm don't work right

why do I always have so much trouble...? given that I didn't solve the problem in my other article, I decided to just code the javascript right into the values... so I have:
OnSuccess="alert('ok')",
OnFailure="alert('failed')",
so my problem is the submission works fine; a record gets inserted into the database and I get a callback... but I get the wrong callback! I get a failure even though the record got inserted. heeeeelp!
You should be able to read data from the response to figure out why it's considered a failure:
OnFailure="handleError",
...
function handleError(ajaxContext) {
var response = ajaxContext.get_response();
var statusCode = response.get_statusCode();
alert("Sorry, the request failed with status code " + statusCode);
}
Alternatively, use Fiddler and look at the response. Make sure the status code, content type and content are all as expected.
ok, I figured out a few things:
OnFailure="handleError" is the correct way to do this (see the other article I mentioned for resolution)
ajaxContext didn't have a get_response() method because I was actually hooking up the function to the OnComplete event instead (my bad)! once hooked up to the OnSuccess, I get my controller's method Json return value natively
I was getting the OnSuccess handler called when the database entry was failing. this is because my controller method was try{} catch{}ing and therefore never failed! me being dopey :(

Resources