Laravel change Content of Mailable before send - php

I currently use Mailable to send mails to users. Data is taken from the database and inserted into the text. I would like to show the text to the user beforehand so that they can make changes if necessary. If the user has made changes, this text should be sent instead of the one generated by Mailable. How can I achieve this?
Current Laravel version: Laravel Framework 9.48.0
Currently, I generate the content using the Blade Template, show this to the user and he can then make changes if necessary. Then I pass the HTML content to the Mailable Layout and send it with that.
I would like to create a separate Mailable for each email template.
Thanks for your help!

I'd save the content of the email which your users changed into a blade template file, so when the text changes you can pass the blade template file to the Mailable view method.
Hope this helps.

Related

Laravel - Standard way to handle a blade for multiple purposes

I am building a send/receive message system. The messages may be created, replied and forwarded. The same blade file is used for all of them. For creation, every field title, body, recipient, attachment is empty but for reply, the recipient is the sender of the message. In forward recipient field is empty. Different situations for fields may happen based on the action.
This is my question, Should I create different blade files for every action or based on the action, I should put if else statement in the blade file and create the corresponding field?
Both approaches have its own drawbacks. for different blade files, It is difficult to maintain the web site. for example changing a color or something in UI, requires changing in every blade file.
thanks in advance.

codeigniter, views are never called directly, can someone explain

I just started to use codeigniter. I need to know the explanation of
Views are never called directly.
Is it mean that i can not use $this->load->view('My_view') into another view?
I created a project in core php and decided to convert into codeigniter. In my project a page has different section so i created a main file recipes.php in views. I also created a folder where i put different section files to include in recipes.php. In my controller i loaded recipe view, it showed the recipe page then inside recipes view i used $this->load->('categorymenu'). It worked fine. I didnt pass any data since this section contains simple html. But im confused that it is not a right way of loading views.
So please can someone explain in detail. Am i doing the right thing or is there another way of doing it.
I also loaded the view in controller and passed to main view in controller which also worked perfect. But as i mentioned im not sure which is the right approach. My apology if this is a stupid question.
As you are naive to Codeigniter no question asked by you is stupid.
Now the answer of your question is that,
You can load a view inside another view and it is absolutely acceptable as there will be some cases when you have to put header in all pages of the web site, that time you have to load the view in another view.
Second is that the correct way to load the view is in the controller. As the controller is the mediator between the model and view. if you want some data of database to be displayed in your page you have to get that data through the function created in the model and then after you can load the view in controller and can pass the data in that.
This is code of controller
public function temp()
{
$data['recs']=$this->my_model->my_function(); //getting data to pass in view
$this->load->view('my_view',$data); //load the view
}

How can I send data from one page to another using Laravel?

So I'm using laravel 5.1 and I'm stuck in a weird situation.
I have 2 models Seasonand Tournament and lets say the url to add a Season model is ..../seasons/add and to view the season would be ..../seasons/(id)... standard stuff right?
But now I want to add a tournament from the link ..../seasons/1 and so I click a link that takes me to ..../tournaments/add... how can I send the Season model to that page without submitting a form with hidden input?
Currently I have this setup ..../seasons/1/tournaments/add using blade to generate the links. But this method just doesn't feel right....
Thanks.
How can I send data from one page to another using Laravel?: I would suggest that you do this from your controller. Take a look at Redirecting With Flashed Session Data, it might come in handy.
From the Flash Data documentation: "[...] it will only be available during the subsequent HTTP request, and then will be deleted [...]"
You can send your model, static values or whatever you want using ->with:
redirect('route')->with('key', 'value');

How to create CakePHP Common Controller Logic

i am currently working on a website. I have made the code such that the contents of the footer is dynamic i.e, it is fetched from database. Now i want to write single code of controller logic for that and use it in the rest of all pages...any help??
Simply fetch the data from one helper function like showFooter().
And you can use it every layout files

CodeIgniter Template Library

I am using CodeIgniter with Template Library and have set up my template view file. Part of my template that doesn't change from page to page displays data from a database.
What is the best way to include this data in my template?
If the content doesn't change very often, something like the user's name, I would store it in the session and call it from there. Otherwise, if you really need to query it on every page request, I would create a base controller (MY_Controller) then create and assign a protected var that you can access from your controllers.

Categories