title: How can I apply SOLID principles to my methods in Laravel
body: <p>Recently I wrote a project as a test.
  In this link you can see my project in <a href="https://github.com/abbasfisal/blog" rel="nofollow noreferrer">GitHub</a></p>
  <p>and my problem is my storePost method which I want to apply SOLID to, but I don't have any idea about it</p>
  <pre><code>    public function storePost(CreatePostRequest $request)
      {
  
  
          try {
              DB::beginTransaction();
  
              /**
               * Tags
               */
              $tags = $request-&gt;tags;
              $tag_ids = [];
              foreach ($tags as $tag) {
                  $tag_ids[] = Tag::query()
                                  -&gt;where(Tag::col_slug, SLUG($tag))
                                  -&gt;orWhere(Tag::col_title, $tag)
                                  -&gt;firstOrCreate([
                                      Tag::col_slug  =&gt; SLUG($tag),
                                      Tag::col_title =&gt; $tag
                                  ]);
              }
  
              /**
               * categories
               */
              $cats = $request-&gt;categories;
              $cat_ids = [];
              foreach ($cats as $cat) {
                  $cat_ids[] = Category::query()
                                       -&gt;findOrFail($cat);
              }
  
  
              $post = Post::query()
                          -&gt;create([
                              Post::col_writer_id =&gt; Auth::id(),
                              Post::col_title     =&gt; $request-&gt;title,
                              Post::col_slug      =&gt; SLUG(rand(0, 3) . $request-&gt;title),
                              Post::col_cover     =&gt; $request-&gt;cover,
                              Post::col_body      =&gt; $request-&gt;body,
                          ]);
  
  
              $post-&gt;categories()
                   -&gt;saveMany($cat_ids);
  
  
              $post-&gt;tags()
                   -&gt;saveMany($tag_ids);
  
              DB::commit();
  
              return redirect()
                  -&gt;route('new.post.writer')
                  -&gt;with('msg', 'New Post Created Successfully');
  
          } catch (\Exception $e) {
              DB::rollBack();
              Log::error($e);
              return redirect()
                  -&gt;route('new.post.writer')
                  -&gt;with('msg', 'Fail To create New Post . Try again');
  
          }
  
      }
  </code></pre>
  <p>and another question is for example if I want to upload and save images to storePost how I should apply SOLID</p>